@flowgram.ai/form-materials 0.4.6 → 0.4.7

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.
Files changed (46) hide show
  1. package/dist/esm/{chunk-6OZSB6PD.js → chunk-727SU246.js} +6 -3
  2. package/dist/esm/chunk-727SU246.js.map +1 -0
  3. package/dist/esm/{chunk-QIJ4QVB2.js → chunk-DEZUEMUM.js} +17 -4
  4. package/dist/esm/chunk-DEZUEMUM.js.map +1 -0
  5. package/dist/esm/{chunk-G4HQ7OSI.js → chunk-MFDEE4HB.js} +5 -5
  6. package/dist/esm/chunk-MFDEE4HB.js.map +1 -0
  7. package/dist/esm/{editor-H2R7JJLO.js → editor-2YHACGQ2.js} +4 -4
  8. package/dist/esm/editor-2YHACGQ2.js.map +1 -0
  9. package/dist/esm/{editor-JX42GFAZ.js → editor-G63XGWH2.js} +5 -5
  10. package/dist/esm/editor-G63XGWH2.js.map +1 -0
  11. package/dist/esm/{editor-YMNCDGUR.js → editor-OXPGKPF5.js} +4 -4
  12. package/dist/esm/editor-OXPGKPF5.js.map +1 -0
  13. package/dist/esm/index.js +24 -23
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/index.d.mts +10 -2
  16. package/dist/index.d.ts +10 -2
  17. package/dist/index.js +336 -313
  18. package/dist/index.js.map +1 -1
  19. package/package.json +7 -7
  20. package/src/components/code-editor/index.tsx +2 -2
  21. package/src/components/display-inputs-values/index.tsx +1 -1
  22. package/src/components/dynamic-value-input/hooks.ts +1 -1
  23. package/src/components/inputs-values-tree/hooks/use-child-list.tsx +1 -1
  24. package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +1 -1
  25. package/src/components/json-editor-with-variables/index.tsx +2 -2
  26. package/src/components/json-schema-editor/hooks.tsx +1 -1
  27. package/src/components/prompt-editor/index.tsx +2 -2
  28. package/src/components/prompt-editor-with-inputs/index.tsx +2 -2
  29. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +1 -1
  30. package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +1 -1
  31. package/src/components/prompt-editor-with-variables/index.tsx +2 -2
  32. package/src/effects/validate-when-variable-sync/index.ts +1 -1
  33. package/src/form-plugins/infer-assign-plugin/index.ts +1 -1
  34. package/src/form-plugins/infer-inputs-plugin/index.ts +1 -1
  35. package/src/hooks/use-object-list/index.tsx +1 -1
  36. package/src/shared/flow-value/utils.ts +1 -1
  37. package/src/shared/format-legacy-refs/index.ts +1 -1
  38. package/src/shared/index.ts +1 -0
  39. package/src/shared/lazy-suspense/index.tsx +28 -0
  40. package/src/validate/validate-flow-value/index.tsx +1 -1
  41. package/dist/esm/chunk-6OZSB6PD.js.map +0 -1
  42. package/dist/esm/chunk-G4HQ7OSI.js.map +0 -1
  43. package/dist/esm/chunk-QIJ4QVB2.js.map +0 -1
  44. package/dist/esm/editor-H2R7JJLO.js.map +0 -1
  45. package/dist/esm/editor-JX42GFAZ.js.map +0 -1
  46. package/dist/esm/editor-YMNCDGUR.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowgram.ai/form-materials",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "homepage": "https://flowgram.ai/",
5
5
  "repository": "https://github.com/bytedance/flowgram.ai",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  "@douyinfe/semi-icons": "^2.80.0",
25
25
  "@douyinfe/semi-illustrations": "^2.80.0",
26
26
  "@douyinfe/semi-ui": "^2.80.0",
27
- "lodash": "^4.17.21",
27
+ "lodash-es": "^4.17.21",
28
28
  "nanoid": "^4.0.2",
29
29
  "commander": "^11.0.0",
30
30
  "chalk": "^5.3.0",
@@ -35,11 +35,11 @@
35
35
  "@codemirror/state": "~6.5.2",
36
36
  "typescript": "^5.8.3",
37
37
  "zod": "^3.24.4",
38
- "@flowgram.ai/editor": "0.4.6",
39
- "@flowgram.ai/json-schema": "0.4.6"
38
+ "@flowgram.ai/editor": "0.4.7",
39
+ "@flowgram.ai/json-schema": "0.4.7"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/lodash": "^4.14.137",
42
+ "@types/lodash-es": "^4.17.12",
43
43
  "@types/node": "^18",
44
44
  "@types/react": "^18",
45
45
  "@types/react-dom": "^18",
@@ -52,8 +52,8 @@
52
52
  "tsup": "^8.0.1",
53
53
  "typescript": "^5.8.3",
54
54
  "vitest": "^0.34.6",
55
- "@flowgram.ai/eslint-config": "0.4.6",
56
- "@flowgram.ai/ts-config": "0.4.6"
55
+ "@flowgram.ai/ts-config": "0.4.7",
56
+ "@flowgram.ai/eslint-config": "0.4.7"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "react": ">=16.8",
@@ -3,9 +3,9 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { lazy } from 'react';
6
+ import { lazySuspense } from '@/shared';
7
7
 
8
- export const CodeEditor = lazy(() =>
8
+ export const CodeEditor = lazySuspense(() =>
9
9
  import('./editor').then((module) => ({ default: module.CodeEditor }))
10
10
  );
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  import React, { useMemo } from 'react';
7
7
 
8
- import { isPlainObject } from 'lodash';
8
+ import { isPlainObject } from 'lodash-es';
9
9
  import { useScopeAvailable } from '@flowgram.ai/editor';
10
10
 
11
11
  import { FlowValueUtils } from '@/shared';
@@ -67,7 +67,7 @@ export function useIncludeSchema(schemaFromProps?: IJsonSchema) {
67
67
  if (schemaFromProps?.type === 'number') {
68
68
  return [schemaFromProps, { type: 'integer' }];
69
69
  }
70
- return { ...schemaFromProps, extra: { ...schemaFromProps?.extra, weak: true } };
70
+ return { ...schemaFromProps, extra: { weak: true, ...schemaFromProps?.extra } };
71
71
  }, [schemaFromProps]);
72
72
 
73
73
  return includeSchema;
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { useMemo } from 'react';
7
7
 
8
- import { isPlainObject } from 'lodash';
8
+ import { isPlainObject } from 'lodash-es';
9
9
 
10
10
  import { FlowValueUtils } from '@/shared';
11
11
  import { useObjectList } from '@/hooks';
@@ -5,7 +5,7 @@
5
5
 
6
6
  import React, { useLayoutEffect } from 'react';
7
7
 
8
- import { isEqual, last } from 'lodash';
8
+ import { isEqual, last } from 'lodash-es';
9
9
  import {
10
10
  BaseVariableField,
11
11
  Disposable,
@@ -3,9 +3,9 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { lazy } from 'react';
6
+ import { lazySuspense } from '@/shared';
7
7
 
8
- export const JsonEditorWithVariables = lazy(() =>
8
+ export const JsonEditorWithVariables = lazySuspense(() =>
9
9
  import('./editor').then((module) => ({ default: module.JsonEditorWithVariables }))
10
10
  );
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { useEffect, useRef, useState } from 'react';
7
7
 
8
- import { difference, omit } from 'lodash';
8
+ import { difference, omit } from 'lodash-es';
9
9
  import { produce } from 'immer';
10
10
  import { IJsonSchema, type JsonSchemaTypeManager, useTypeManager } from '@flowgram.ai/json-schema';
11
11
 
@@ -3,9 +3,9 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { lazy } from 'react';
6
+ import { lazySuspense } from '@/shared';
7
7
 
8
- export const PromptEditor = lazy(() =>
8
+ export const PromptEditor = lazySuspense(() =>
9
9
  import('./editor').then((module) => ({ default: module.PromptEditor }))
10
10
  );
11
11
 
@@ -3,9 +3,9 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { lazy } from 'react';
6
+ import { lazySuspense } from '@/shared';
7
7
 
8
- export const PromptEditorWithInputs = lazy(() =>
8
+ export const PromptEditorWithInputs = lazySuspense(() =>
9
9
  import('./editor').then((module) => ({ default: module.PromptEditorWithInputs }))
10
10
  );
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  import React, { useMemo } from 'react';
7
7
 
8
- import { isPlainObject, last } from 'lodash';
8
+ import { isPlainObject, last } from 'lodash-es';
9
9
  import {
10
10
  type ArrayType,
11
11
  ASTMatch,
@@ -5,7 +5,7 @@
5
5
 
6
6
  import React, { useLayoutEffect } from 'react';
7
7
 
8
- import { isEqual, last } from 'lodash';
8
+ import { isEqual, last } from 'lodash-es';
9
9
  import {
10
10
  BaseVariableField,
11
11
  Disposable,
@@ -3,9 +3,9 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { lazy } from 'react';
6
+ import { lazySuspense } from '@/shared';
7
7
 
8
- export const PromptEditorWithVariables = lazy(() =>
8
+ export const PromptEditorWithVariables = lazySuspense(() =>
9
9
  import('./editor').then((module) => ({ default: module.PromptEditorWithVariables }))
10
10
  );
11
11
 
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { isEmpty } from 'lodash';
6
+ import { isEmpty } from 'lodash-es';
7
7
  import {
8
8
  DataEvent,
9
9
  Effect,
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { set, uniqBy } from 'lodash';
6
+ import { set, uniqBy } from 'lodash-es';
7
7
  import { JsonSchemaUtils } from '@flowgram.ai/json-schema';
8
8
  import {
9
9
  ASTFactory,
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { get, set } from 'lodash';
6
+ import { get, set } from 'lodash-es';
7
7
  import { defineFormPluginCreator, getNodePrivateScope, getNodeScope } from '@flowgram.ai/editor';
8
8
 
9
9
  import { FlowValueUtils } from '@/shared';
@@ -6,7 +6,7 @@
6
6
  import { useEffect, useRef, useState } from 'react';
7
7
 
8
8
  import { nanoid } from 'nanoid';
9
- import { difference, get, isObject, set } from 'lodash';
9
+ import { difference, get, isObject, set } from 'lodash-es';
10
10
 
11
11
  function genId() {
12
12
  return nanoid();
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { isArray, isObject, isPlainObject, uniq } from 'lodash';
6
+ import { isArray, isObject, isPlainObject, uniq } from 'lodash-es';
7
7
  import { IJsonSchema, JsonSchemaUtils } from '@flowgram.ai/json-schema';
8
8
  import { Scope } from '@flowgram.ai/editor';
9
9
 
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { isObject } from 'lodash';
6
+ import { isObject } from 'lodash-es';
7
7
 
8
8
  interface LegacyFlowRefValueSchema {
9
9
  type: 'ref';
@@ -7,3 +7,4 @@ export * from './format-legacy-refs';
7
7
  export * from './inject-material';
8
8
  export * from './flow-value';
9
9
  export * from './polyfill-create-root';
10
+ export * from './lazy-suspense';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React, { ComponentType, lazy, Suspense } from 'react';
7
+
8
+ import { Skeleton } from '@douyinfe/semi-ui';
9
+
10
+ export function withSuspense<T extends ComponentType<any>>(
11
+ Component: T,
12
+ fallback?: React.ReactNode
13
+ ): T {
14
+ const WithSuspenseComponent: T = ((props: any) => (
15
+ <Suspense fallback={fallback || <Skeleton.Paragraph style={{ width: '100%' }} rows={1} />}>
16
+ <Component {...props} />
17
+ </Suspense>
18
+ )) as any;
19
+
20
+ return WithSuspenseComponent;
21
+ }
22
+
23
+ export function lazySuspense<T extends ComponentType<any>>(
24
+ params: Parameters<typeof lazy<T>>[0],
25
+ fallback?: React.ReactNode
26
+ ) {
27
+ return withSuspense(lazy(params), fallback);
28
+ }
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { isNil } from 'lodash';
6
+ import { isNil } from 'lodash-es';
7
7
  import { FeedbackLevel, FlowNodeEntity, getNodeScope } from '@flowgram.ai/editor';
8
8
 
9
9
  import { IFlowValue } from '@/typings';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/prompt-editor/index.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { lazy } from 'react';\n\nexport const PromptEditor = lazy(() =>\n import('./editor').then((module) => ({ default: module.PromptEditor }))\n);\n\nexport type { PromptEditorPropsType } from './editor';\n"],"mappings":";AAKA,SAAS,YAAY;AAEd,IAAM,eAAe;AAAA,EAAK,MAC/B,OAAO,sBAAU,EAAE,KAAK,CAAC,YAAY,EAAE,SAAS,OAAO,aAAa,EAAE;AACxE;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/code-editor/index.tsx","../../src/components/code-editor-mini/index.tsx","../../src/plugins/json-schema-preset/create-type-preset-plugin.tsx","../../src/plugins/json-schema-preset/type-definition/index.tsx","../../src/plugins/json-schema-preset/type-definition/string.tsx","../../src/plugins/json-schema-preset/type-definition/object.tsx","../../src/plugins/json-schema-preset/type-definition/number.tsx","../../src/plugins/json-schema-preset/type-definition/integer.tsx","../../src/plugins/json-schema-preset/type-definition/boolean.tsx","../../src/plugins/json-schema-preset/type-definition/array.tsx","../../src/plugins/json-schema-preset/index.tsx","../../src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts","../../src/components/variable-selector/use-variable-tree.tsx","../../src/components/variable-selector/index.tsx","../../src/components/variable-selector/styles.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { lazy } from 'react';\n\nexport const CodeEditor = lazy(() =>\n import('./editor').then((module) => ({ default: module.CodeEditor }))\n);\n\nexport type { CodeEditorPropsType } from './editor';\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React from 'react';\n\nimport styled from 'styled-components';\n\nimport { CodeEditor, type CodeEditorPropsType } from '@/components/code-editor';\n\nconst UIMini = styled.div`\n .ͼ1 .cm-content {\n }\n`;\n\nexport function CodeEditorMini(props: CodeEditorPropsType) {\n return (\n <UIMini>\n <CodeEditor\n {...props}\n options={{\n lineNumbersGutter: false,\n foldGutter: false,\n minHeight: 24,\n ...(props.options || {}),\n }}\n />\n </UIMini>\n );\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport {\n BaseTypeManager,\n jsonSchemaContainerModule,\n JsonSchemaTypeManager,\n} from '@flowgram.ai/json-schema';\nimport { definePluginCreator } from '@flowgram.ai/editor';\n\nimport { jsonSchemaTypePreset } from './type-definition';\nimport { JsonSchemaTypeRegistry } from './manager';\n\nexport const createTypePresetPlugin = definePluginCreator<{\n types?: Partial<JsonSchemaTypeRegistry> & Pick<JsonSchemaTypeRegistry, 'type'>[];\n unregisterTypes?: string[];\n}>({\n onInit(ctx, opts) {\n const typeManager = ctx.get(BaseTypeManager) as JsonSchemaTypeManager;\n jsonSchemaTypePreset.forEach((_type) => typeManager.register(_type));\n\n opts.types?.forEach((_type) => typeManager.register(_type));\n opts.unregisterTypes?.forEach((_type) => typeManager.unregister(_type));\n },\n containerModules: [jsonSchemaContainerModule],\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { jsonSchemaTypeManager } from '@flowgram.ai/json-schema';\n\nimport { stringRegistry } from './string';\nimport { objectRegistry } from './object';\nimport { numberRegistry } from './number';\nimport { integerRegistry } from './integer';\nimport { booleanRegistry } from './boolean';\nimport { arrayRegistry } from './array';\n\nexport const jsonSchemaTypePreset = [\n stringRegistry,\n objectRegistry,\n numberRegistry,\n integerRegistry,\n booleanRegistry,\n arrayRegistry,\n];\n\njsonSchemaTypePreset.forEach((_type) => jsonSchemaTypeManager.register(_type));\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n/* eslint-disable react/prop-types */\nimport React from 'react';\n\nimport { I18n } from '@flowgram.ai/editor';\nimport { Input, TextArea } from '@douyinfe/semi-ui';\n\nimport { type JsonSchemaTypeRegistry } from '../manager';\n\nexport const stringRegistry: Partial<JsonSchemaTypeRegistry> = {\n type: 'string',\n ConstantRenderer: (props) =>\n props?.enableMultiLineStr ? (\n <TextArea\n autosize\n rows={1}\n placeholder={I18n.t('Please Input String')}\n disabled={props.readonly}\n {...props}\n />\n ) : (\n <Input\n size=\"small\"\n placeholder={I18n.t('Please Input String')}\n disabled={props.readonly}\n {...props}\n />\n ),\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n/* eslint-disable react/prop-types */\nimport React from 'react';\n\nimport { I18n } from '@flowgram.ai/editor';\n\nimport { CodeEditorMini } from '@/components/code-editor-mini';\n\nimport { type JsonSchemaTypeRegistry } from '../manager';\n\nexport const objectRegistry: Partial<JsonSchemaTypeRegistry> = {\n type: 'object',\n ConstantRenderer: (props) => (\n <CodeEditorMini\n value={props.value}\n onChange={(v) => props.onChange?.(v)}\n languageId=\"json\"\n placeholder={I18n.t('Please Input Object')}\n readonly={props.readonly}\n />\n ),\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n/* eslint-disable react/prop-types */\nimport React from 'react';\n\nimport { I18n } from '@flowgram.ai/editor';\nimport { InputNumber } from '@douyinfe/semi-ui';\n\nimport { type JsonSchemaTypeRegistry } from '../manager';\n\nexport const numberRegistry: Partial<JsonSchemaTypeRegistry> = {\n type: 'number',\n ConstantRenderer: (props) => (\n <InputNumber\n placeholder={I18n.t('Please Input Number')}\n size=\"small\"\n disabled={props.readonly}\n hideButtons\n {...props}\n />\n ),\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n/* eslint-disable react/prop-types */\nimport React from 'react';\n\nimport { I18n } from '@flowgram.ai/editor';\nimport { InputNumber } from '@douyinfe/semi-ui';\n\nimport { type JsonSchemaTypeRegistry } from '../manager';\n\nexport const integerRegistry: Partial<JsonSchemaTypeRegistry> = {\n type: 'integer',\n ConstantRenderer: (props) => (\n <InputNumber\n placeholder={I18n.t('Please Input Integer')}\n size=\"small\"\n disabled={props.readonly}\n precision={0}\n {...props}\n />\n ),\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n/* eslint-disable react/prop-types */\nimport React from 'react';\n\nimport { I18n } from '@flowgram.ai/editor';\nimport { Select } from '@douyinfe/semi-ui';\n\nimport { type JsonSchemaTypeRegistry } from '../manager';\n\nexport const booleanRegistry: Partial<JsonSchemaTypeRegistry> = {\n type: 'boolean',\n ConstantRenderer: (props) => {\n const { value, onChange, ...rest } = props;\n return (\n <Select\n placeholder={I18n.t('Please Select Boolean')}\n size=\"small\"\n disabled={props.readonly}\n optionList={[\n { label: I18n.t('True'), value: 1 },\n { label: I18n.t('False'), value: 0 },\n ]}\n value={value ? 1 : 0}\n onChange={(value) => onChange?.(!!value)}\n {...rest}\n />\n );\n },\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n/* eslint-disable react/prop-types */\nimport React from 'react';\n\nimport { I18n } from '@flowgram.ai/editor';\n\nimport { CodeEditorMini } from '@/components/code-editor-mini';\n\nimport { type JsonSchemaTypeRegistry } from '../manager';\n\nexport const arrayRegistry: Partial<JsonSchemaTypeRegistry> = {\n type: 'array',\n ConstantRenderer: (props) => (\n <CodeEditorMini\n value={props.value}\n languageId=\"json\"\n onChange={(v) => props.onChange?.(v)}\n placeholder={I18n.t('Please Input Array')}\n readonly={props.readonly}\n />\n ),\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\nimport React from 'react';\n\nimport {\n type IJsonSchema,\n JsonSchemaUtils,\n useTypeManager as useOriginTypeManager,\n TypePresetProvider as OriginTypePresetProvider,\n JsonSchemaTypeManager,\n type JsonSchemaBasicType,\n} from '@flowgram.ai/json-schema';\n\nimport { jsonSchemaTypePreset } from './type-definition';\nimport { type JsonSchemaTypeRegistry, type ConstantRendererProps } from './manager';\nimport { createTypePresetPlugin } from './create-type-preset-plugin';\n\nconst useTypeManager = () =>\n useOriginTypeManager() as JsonSchemaTypeManager<IJsonSchema, JsonSchemaTypeRegistry>;\n\nconst JsonSchemaTypePresetProvider = ({\n types = [],\n children,\n}: React.PropsWithChildren<{ types: JsonSchemaTypeRegistry[] }>) => (\n <OriginTypePresetProvider types={[...jsonSchemaTypePreset, ...types]}>\n {children}\n </OriginTypePresetProvider>\n);\n\nexport {\n createTypePresetPlugin,\n useTypeManager,\n JsonSchemaTypePresetProvider,\n IJsonSchema,\n JsonSchemaUtils,\n JsonSchemaTypeRegistry,\n ConstantRendererProps,\n JsonSchemaBasicType,\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport {\n ASTMatch,\n definePluginCreator,\n type GlobalEventActionType,\n VariableEngine,\n} from '@flowgram.ai/editor';\n\nexport const createDisableDeclarationPlugin = definePluginCreator<void>({\n onInit(ctx) {\n const variableEngine = ctx.get(VariableEngine);\n\n const handleEvent = (action: GlobalEventActionType) => {\n if (ASTMatch.isVariableDeclaration(action.ast)) {\n if (!action.ast.meta?.disabled) {\n action.ast.updateMeta({\n ...(action.ast.meta || {}),\n disabled: true,\n });\n }\n }\n };\n\n variableEngine.onGlobalEvent('NewAST', handleEvent);\n variableEngine.onGlobalEvent('UpdateAST', handleEvent);\n },\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useCallback } from 'react';\n\nimport { IJsonSchema, JsonSchemaUtils } from '@flowgram.ai/json-schema';\nimport { ASTMatch, BaseVariableField, useAvailableVariables } from '@flowgram.ai/editor';\nimport { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';\nimport { Icon } from '@douyinfe/semi-ui';\n\nimport { useTypeManager } from '@/plugins';\n\ntype VariableField = BaseVariableField<{\n icon?: string | JSX.Element;\n title?: string;\n disabled?: boolean;\n}>;\n\nexport function useVariableTree(params: {\n includeSchema?: IJsonSchema | IJsonSchema[];\n excludeSchema?: IJsonSchema | IJsonSchema[];\n customSkip?: (variable: VariableField) => boolean;\n}): TreeNodeData[] {\n const { includeSchema, excludeSchema, customSkip } = params;\n\n const typeManager = useTypeManager();\n const variables = useAvailableVariables();\n\n const getVariableTypeIcon = useCallback((variable: VariableField) => {\n if (variable.meta?.icon) {\n if (typeof variable.meta.icon === 'string') {\n return <img style={{ marginRight: 8 }} width={12} height={12} src={variable.meta.icon} />;\n }\n\n return variable.meta.icon;\n }\n\n const schema = JsonSchemaUtils.astToSchema(variable.type, { drilldownObject: false });\n\n return <Icon size=\"small\" svg={typeManager.getDisplayIcon(schema || {})} />;\n }, []);\n\n const renderVariable = (\n variable: VariableField,\n parentFields: VariableField[] = []\n ): TreeNodeData | null => {\n let type = variable?.type;\n\n if (!type) {\n return null;\n }\n\n let children: TreeNodeData[] | undefined;\n\n if (ASTMatch.isObject(type)) {\n children = (type.properties || [])\n .map((_property) => renderVariable(_property as VariableField, [...parentFields, variable]))\n .filter(Boolean) as TreeNodeData[];\n }\n\n const keyPath = [...parentFields.map((_field) => _field.key), variable.key];\n const key = keyPath.join('.');\n\n const isSchemaInclude = includeSchema\n ? JsonSchemaUtils.isASTMatchSchema(type, includeSchema)\n : true;\n const isSchemaExclude = excludeSchema\n ? JsonSchemaUtils.isASTMatchSchema(type, excludeSchema)\n : false;\n const isCustomSkip = customSkip ? customSkip(variable) : false;\n\n // disabled in meta when created\n const isMetaDisabled = variable.meta?.disabled;\n\n const isSchemaMatch = isSchemaInclude && !isSchemaExclude && !isCustomSkip && !isMetaDisabled;\n\n // If not match, and no children, return null\n if (!isSchemaMatch && !children?.length) {\n return null;\n }\n\n return {\n key: key,\n label: variable.meta?.title || variable.key,\n value: key,\n keyPath,\n icon: getVariableTypeIcon(variable),\n children,\n disabled: !isSchemaMatch,\n rootMeta: parentFields[0]?.meta || variable.meta,\n isRoot: !parentFields?.length,\n };\n };\n\n return [...variables.slice(0).reverse()]\n .map((_variable) => renderVariable(_variable as VariableField))\n .filter(Boolean) as TreeNodeData[];\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 { IJsonSchema } from '@flowgram.ai/json-schema';\nimport { I18n } from '@flowgram.ai/editor';\nimport { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';\nimport { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';\nimport { Popover } from '@douyinfe/semi-ui';\nimport { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';\n\nimport { createInjectMaterial } from '@/shared';\n\nimport { useVariableTree } from './use-variable-tree';\nimport { UIPopoverContent, UIRootTitle, UITag, UITreeSelect, UIVarName } from './styles';\n\nexport interface VariableSelectorProps {\n value?: string[];\n config?: {\n placeholder?: string;\n notFoundContent?: string;\n };\n onChange: (value?: string[]) => void;\n includeSchema?: IJsonSchema | IJsonSchema[];\n excludeSchema?: IJsonSchema | IJsonSchema[];\n readonly?: boolean;\n hasError?: boolean;\n style?: React.CSSProperties;\n triggerRender?: (props: TriggerRenderProps) => React.ReactNode;\n}\n\nexport { useVariableTree };\n\nexport const VariableSelector = ({\n value,\n config = {},\n onChange,\n style,\n readonly = false,\n includeSchema,\n excludeSchema,\n hasError,\n triggerRender,\n}: VariableSelectorProps) => {\n const treeData = useVariableTree({ includeSchema, excludeSchema });\n\n const treeValue = useMemo(() => {\n if (typeof value === 'string') {\n console.warn(\n 'The Value of VariableSelector is a string, it should be an ARRAY. \\n',\n 'Please check the value of VariableSelector \\n'\n );\n return value;\n }\n return value?.join('.');\n }, [value]);\n\n const renderIcon = (icon: string | JSX.Element) => {\n if (typeof icon === 'string') {\n return <img style={{ marginRight: 8 }} width={12} height={12} src={icon} />;\n }\n\n return icon;\n };\n\n return (\n <>\n <UITreeSelect\n dropdownMatchSelectWidth={false}\n disabled={readonly}\n treeData={treeData}\n size=\"small\"\n value={treeValue}\n clearIcon={null}\n $error={hasError}\n style={style}\n validateStatus={hasError ? 'error' : undefined}\n onChange={(_, _config) => {\n onChange((_config as TreeNodeData).keyPath as string[]);\n }}\n renderSelectedItem={(_option: TreeNodeData) => {\n if (!_option?.keyPath) {\n return (\n <UITag\n prefixIcon={<IconIssueStroked />}\n color=\"amber\"\n closable={!readonly}\n onClose={() => onChange(undefined)}\n >\n {config?.notFoundContent ?? 'Undefined'}\n </UITag>\n );\n }\n\n const rootIcon = renderIcon(_option.rootMeta?.icon || _option?.icon);\n\n const rootTitle = (\n <UIRootTitle>\n {_option.rootMeta?.title\n ? `${_option.rootMeta?.title} ${_option.isRoot ? '' : '-'} `\n : null}\n </UIRootTitle>\n );\n\n return (\n <div>\n <Popover\n content={\n <UIPopoverContent>\n {rootIcon}\n {rootTitle}\n <UIVarName>{_option.keyPath.slice(1).join('.')}</UIVarName>\n </UIPopoverContent>\n }\n >\n <UITag\n prefixIcon={rootIcon}\n closable={!readonly}\n onClose={() => onChange(undefined)}\n >\n {rootTitle}\n {!_option.isRoot && <UIVarName $inSelector>{_option.label}</UIVarName>}\n </UITag>\n </Popover>\n </div>\n );\n }}\n showClear={false}\n arrowIcon={<IconChevronDownStroked size=\"small\" />}\n triggerRender={triggerRender}\n placeholder={config?.placeholder ?? I18n.t('Select Variable')}\n />\n </>\n );\n};\n\nVariableSelector.renderKey = 'variable-selector-render-key';\nexport const InjectVariableSelector = createInjectMaterial(VariableSelector);\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport styled, { css } from 'styled-components';\nimport { Tag, TreeSelect } from '@douyinfe/semi-ui';\n\nexport const UIRootTitle = styled.div`\n margin-right: 4px;\n min-width: 20px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: var(--semi-color-text-2);\n`;\n\nexport const UIVarName = styled.div<{ $inSelector?: boolean }>`\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n\n ${({ $inSelector }) =>\n $inSelector &&\n css`\n min-width: 50%;\n `}\n`;\n\nexport const UITag = styled(Tag)`\n width: 100%;\n display: flex;\n align-items: center;\n justify-content: flex-start;\n\n & .semi-tag-content-center {\n justify-content: flex-start;\n }\n\n &.semi-tag {\n margin: 0;\n height: 22px;\n }\n`;\n\nexport const UITreeSelect = styled(TreeSelect)<{ $error?: boolean }>`\n outline: ${({ $error }) => ($error ? '1px solid red' : 'none')};\n\n & .semi-tree-select-selection {\n padding: 0px;\n height: 22px;\n }\n\n & .semi-tree-select-selection-content {\n width: 100%;\n }\n\n & .semi-tree-select-selection-placeholder {\n padding-left: 10px;\n }\n`;\n\nexport const UIPopoverContent = styled.div`\n padding: 10px;\n display: inline-flex;\n align-items: center;\n justify-content: flex-start;\n white-space: nowrap;\n`;\n"],"mappings":";;;;;AAKA,SAAS,YAAY;AAEd,IAAM,aAAa;AAAA,EAAK,MAC7B,OAAO,sBAAU,EAAE,KAAK,CAAC,YAAY,EAAE,SAAS,OAAO,WAAW,EAAE;AACtE;;;ACJA,OAAO,WAAW;AAElB,OAAO,YAAY;AAInB,IAAM,SAAS,OAAO;AAAA;AAAA;AAAA;AAKf,SAAS,eAAe,OAA4B;AACzD,SACE,oCAAC,cACC;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,SAAS;AAAA,QACP,mBAAmB;AAAA,QACnB,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,GAAI,MAAM,WAAW,CAAC;AAAA,MACxB;AAAA;AAAA,EACF,CACF;AAEJ;;;ACzBA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,2BAA2B;;;ACLpC,SAAS,6BAA6B;;;ACCtC,OAAOA,YAAW;AAElB,SAAS,YAAY;AACrB,SAAS,OA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WAAW,WAAW,QAAQ,UAAU,QAAQ,SAAS,IAAI;AAEnE,cAAM,YACJ,gBAAAA,QAAA,cAAC,mBACE,QAAQ,UAAU,QACf,GAAG,QAAQ,UAAU,KAAK,IAAI,QAAQ,SAAS,KAAK,GAAG,MACvD,IACN;AAGF,eACE,gBAAAA,QAAA,cAAC,aACC,gBAAAA,QAAA;AAAA,UAAC;AAAA;AAAA,YACC,SACE,gBAAAA,QAAA,cAAC,wBACE,UACA,WACD,gBAAAA,QAAA,cAAC,iBAAW,QAAQ,QAAQ,MAAM,CAAC,EAAE,KAAK,GAAG,CAAE,CACjD;AAAA;AAAA,UAGF,gBAAAA,QAAA;AAAA,YAAC;AAAA;AAAA,cACC,YAAY;AAAA,cACZ,UAAU,CAAC;AAAA,cACX,SAAS,MAAM,SAAS,MAAS;AAAA;AAAA,YAEhC;AAAA,YACA,CAAC,QAAQ,UAAU,gBAAAA,QAAA,cAAC,aAAU,aAAW,QAAE,QAAQ,KAAM;AAAA,UAC5D;AAAA,QACF,CACF;AAAA,MAEJ;AAAA,MACA,WAAW;AAAA,MACX,WAAW,gBAAAA,QAAA,cAAC,0BAAuB,MAAK,SAAQ;AAAA,MAChD;AAAA,MACA,aAAa,QAAQ,eAAeC,MAAK,EAAE,iBAAiB;AAAA;AAAA,EAC9D,CACF;AAEJ;AAEA,iBAAiB,YAAY;AACtB,IAAM,yBAAyB,qBAAqB,gBAAgB;","names":["React","React","I18n","React","I18n","React","I18n","React","I18n","InputNumber","React","I18n","value","React","I18n","React","I18n","React","React","definePluginCreator","React","JsonSchemaUtils","ASTMatch","React","JsonSchemaUtils","ASTMatch","React","I18n","styled","React","I18n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/shared/format-legacy-refs/index.ts","../../src/shared/inject-material/index.tsx","../../src/shared/flow-value/utils.ts","../../src/shared/flow-value/schema.ts","../../src/shared/polyfill-create-root/index.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { isObject } from 'lodash';\n\ninterface LegacyFlowRefValueSchema {\n type: 'ref';\n content: string;\n}\n\ninterface NewFlowRefValueSchema {\n type: 'ref';\n content: string[];\n}\n\n/**\n * In flowgram 0.2.0, for introducing Loop variable functionality,\n * the FlowRefValueSchema type definition is updated:\n *\n * interface LegacyFlowRefValueSchema {\n * type: 'ref';\n * content: string;\n * }\n *\n * interface NewFlowRefValueSchema {\n * type: 'ref';\n * content: string[];\n * }\n *\n *\n * For making sure backend json will not be changed, we provide format legacy ref utils for updating the formData\n *\n * How to use:\n *\n * 1. Call formatLegacyRefOnSubmit on the formData before submitting\n * 2. Call formatLegacyRefOnInit on the formData after submitting\n *\n * Example:\n * import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram.ai/form-materials';\n * formMeta: {\n * formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),\n * formatOnInit: (data) => formatLegacyRefOnInit(data),\n * }\n */\nexport function formatLegacyRefOnSubmit(value: any): any {\n if (isObject(value)) {\n if (isLegacyFlowRefValueSchema(value)) {\n return formatLegacyRefToNewRef(value);\n }\n\n return Object.fromEntries(\n Object.entries(value).map(([key, value]: [string, any]) => [\n key,\n formatLegacyRefOnSubmit(value),\n ])\n );\n }\n\n if (Array.isArray(value)) {\n return value.map(formatLegacyRefOnSubmit);\n }\n\n return value;\n}\n\n/**\n * In flowgram 0.2.0, for introducing Loop variable functionality,\n * the FlowRefValueSchema type definition is updated:\n *\n * interface LegacyFlowRefValueSchema {\n * type: 'ref';\n * content: string;\n * }\n *\n * interface NewFlowRefValueSchema {\n * type: 'ref';\n * content: string[];\n * }\n *\n *\n * For making sure backend json will not be changed, we provide format legacy ref utils for updating the formData\n *\n * How to use:\n *\n * 1. Call formatLegacyRefOnSubmit on the formData before submitting\n * 2. Call formatLegacyRefOnInit on the formData after submitting\n *\n * Example:\n * import { formatLegacyRefOnSubmit, formatLegacyRefOnInit } from '@flowgram.ai/form-materials';\n *\n * formMeta: {\n * formatOnSubmit: (data) => formatLegacyRefOnSubmit(data),\n * formatOnInit: (data) => formatLegacyRefOnInit(data),\n * }\n */\nexport function formatLegacyRefOnInit(value: any): any {\n if (isObject(value)) {\n if (isNewFlowRefValueSchema(value)) {\n return formatNewRefToLegacyRef(value);\n }\n\n return Object.fromEntries(\n Object.entries(value).map(([key, value]: [string, any]) => [\n key,\n formatLegacyRefOnInit(value),\n ])\n );\n }\n\n if (Array.isArray(value)) {\n return value.map(formatLegacyRefOnInit);\n }\n\n return value;\n}\n\nexport function isLegacyFlowRefValueSchema(value: any): value is LegacyFlowRefValueSchema {\n return (\n isObject(value) &&\n Object.keys(value).length === 2 &&\n (value as any).type === 'ref' &&\n typeof (value as any).content === 'string'\n );\n}\n\nexport function isNewFlowRefValueSchema(value: any): value is NewFlowRefValueSchema {\n return (\n isObject(value) &&\n Object.keys(value).length === 2 &&\n (value as any).type === 'ref' &&\n Array.isArray((value as any).content)\n );\n}\n\nexport function formatLegacyRefToNewRef(value: LegacyFlowRefValueSchema) {\n const keyPath = value.content.split('.');\n\n if (keyPath[1] === 'outputs') {\n return {\n type: 'ref',\n content: [`${keyPath[0]}.${keyPath[1]}`, ...(keyPath.length > 2 ? keyPath.slice(2) : [])],\n };\n }\n\n return {\n type: 'ref',\n content: keyPath,\n };\n}\n\nexport function formatNewRefToLegacyRef(value: NewFlowRefValueSchema) {\n return {\n type: 'ref',\n content: value.content.join('.'),\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 {\n FlowRendererComponentType,\n FlowRendererRegistry,\n usePlaygroundContainer,\n} from '@flowgram.ai/editor';\n\n/**\n * Creates a material component wrapper with dependency injection support\n *\n * This Higher-Order Component (HOC) implements a dynamic component replacement mechanism\n * for material components. It automatically checks if a custom renderer is registered\n * in the editor context, using the injected component if available, otherwise\n * falling back to the default component.\n *\n * @example\n * ```tsx\n * // 1.Create an injectable material component\n * const InjectVariableSelector = createInjectMaterial(VariableSelector)\n *\n * // 2. Register custom components in editor\n * // Configure in use-editor-props.tsx:\n * const editorProps = {\n * materials: {\n * components: {\n * [VariableSelector.renderKey]: YourCustomVariableSelector\n * }\n * }\n * }\n * ```\n *\n * @description\n * Data flow explanation:\n * - Register components to FlowRendererRegistry in use-editor-props\n * - InjectMaterial reads renderers from FlowRendererRegistry\n * - If registered renderer exists and type is REACT, use injected component\n * - If not exists or type mismatch, fallback to default component\n *\n * @param Component - Default React component\n * @param params - Optional parameters\n * @param params.renderKey - Custom render key name, highest priority\n * @returns Wrapper component with dependency injection support\n */\nexport function createInjectMaterial<Props>(\n Component: React.FC<Props> & { renderKey?: string },\n params?: {\n renderKey?: string;\n }\n): React.FC<Props> {\n const InjectComponent: React.FC<Props> = (props) => {\n const container = usePlaygroundContainer();\n\n // Check if renderer registry is bound in container\n if (!container?.isBound(FlowRendererRegistry)) {\n // If no registry, use default component directly\n return React.createElement(Component as (props?: any) => any, { ...props });\n }\n\n // Get renderer registry instance\n const rendererRegistry = container.get(FlowRendererRegistry);\n\n // Determine render key: prioritize param specified, then component renderKey, finally component name\n const renderKey = params?.renderKey || Component.renderKey || Component.name || '';\n\n // Get corresponding renderer from registry\n const renderer = rendererRegistry.tryToGetRendererComponent(renderKey);\n\n // Check if renderer exists and type is React component\n if (renderer?.type !== FlowRendererComponentType.REACT) {\n // If no suitable renderer found, fallback to default component\n return React.createElement(Component as (props?: any) => any, { ...props });\n }\n\n // Render using injected React component\n return React.createElement(renderer.renderer, {\n ...props,\n });\n };\n\n return InjectComponent;\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { isArray, isObject, isPlainObject, uniq } from 'lodash';\nimport { IJsonSchema, JsonSchemaUtils } from '@flowgram.ai/json-schema';\nimport { Scope } from '@flowgram.ai/editor';\n\nimport {\n IFlowConstantValue,\n IFlowRefValue,\n IFlowExpressionValue,\n IFlowTemplateValue,\n IFlowValue,\n IFlowConstantRefValue,\n FlowValueType,\n} from '@/typings';\n\nimport { constantSchema, refSchema, expressionSchema, templateSchema } from './schema';\n\nexport namespace FlowValueUtils {\n /**\n * Check if the value is a constant type\n */\n export function isConstant(value: any): value is IFlowConstantValue {\n return constantSchema.safeParse(value).success;\n }\n\n /**\n * Check if the value is a reference type\n */\n export function isRef(value: any): value is IFlowRefValue {\n return refSchema.safeParse(value).success;\n }\n\n /**\n * Check if the value is an expression type\n */\n export function isExpression(value: any): value is IFlowExpressionValue {\n return expressionSchema.safeParse(value).success;\n }\n\n /**\n * Check if the value is a template type\n */\n export function isTemplate(value: any): value is IFlowTemplateValue {\n return templateSchema.safeParse(value).success;\n }\n\n /**\n * Check if the value is either a constant or reference type\n */\n export function isConstantOrRef(value: any): value is IFlowConstantRefValue {\n return isConstant(value) || isRef(value);\n }\n\n /**\n * Check if the value is a valid flow value type\n */\n export function isFlowValue(value: any): value is IFlowValue {\n return isConstant(value) || isRef(value) || isExpression(value) || isTemplate(value);\n }\n\n /**\n * Traverse all flow values in the given value\n * @param value The value to traverse\n * @param options The options to traverse\n * @returns A generator of flow values\n */\n export function* traverse(\n value: any,\n options: {\n includeTypes?: FlowValueType[];\n path?: string;\n }\n ): Generator<{ value: IFlowValue; path: string }> {\n const { includeTypes = ['ref', 'template'], path = '' } = options;\n\n if (isPlainObject(value)) {\n if (isRef(value) && includeTypes.includes('ref')) {\n yield { value, path };\n return;\n }\n\n if (isTemplate(value) && includeTypes.includes('template')) {\n yield { value, path };\n return;\n }\n\n if (isExpression(value) && includeTypes.includes('expression')) {\n yield { value, path };\n return;\n }\n\n if (isConstant(value) && includeTypes.includes('constant')) {\n yield { value, path };\n return;\n }\n\n for (const [_key, _value] of Object.entries(value)) {\n yield* traverse(_value, { ...options, path: `${path}.${_key}` });\n }\n return;\n }\n\n if (isArray(value)) {\n for (const [_idx, _value] of value.entries()) {\n yield* traverse(_value, { ...options, path: `${path}[${_idx}]` });\n }\n return;\n }\n\n return;\n }\n\n /**\n * Get all key paths in the template value\n * @param value The template value\n * @returns A list of key paths\n */\n export function getTemplateKeyPaths(value: IFlowTemplateValue) {\n // find all keyPath wrapped in {{}}\n const keyPathReg = /\\{\\{([^\\}\\{]+)\\}\\}/g;\n return uniq(value.content?.match(keyPathReg) || []).map((_keyPath) =>\n _keyPath.slice(2, -2).split('.')\n );\n }\n\n /**\n * Infer the schema of the constant value\n * @param value\n * @returns\n */\n export function inferConstantJsonSchema(value: IFlowConstantValue): IJsonSchema | undefined {\n if (value?.schema) {\n return value.schema;\n }\n\n if (typeof value.content === 'string') {\n return {\n type: 'string',\n };\n }\n\n if (typeof value.content === 'number') {\n return {\n type: 'number',\n };\n }\n\n if (typeof value.content === 'boolean') {\n return {\n type: 'boolean',\n };\n }\n\n if (isObject(value.content)) {\n return {\n type: 'object',\n };\n }\n return undefined;\n }\n\n /**\n * Infer the schema of the flow value\n * @param values The flow value or object contains flow value\n * @param scope\n * @returns\n */\n export function inferJsonSchema(values: any, scope: Scope): IJsonSchema | undefined {\n if (isPlainObject(values)) {\n if (isConstant(values)) {\n return inferConstantJsonSchema(values);\n }\n\n if (isRef(values)) {\n const variable = scope.available.getByKeyPath(values?.content);\n const schema = variable?.type ? JsonSchemaUtils.astToSchema(variable?.type) : undefined;\n\n return schema;\n }\n\n if (isTemplate(values)) {\n return { type: 'string' };\n }\n\n return {\n type: 'object',\n properties: Object.keys(values).reduce((acc, key) => {\n const schema = inferJsonSchema((values as any)[key], scope);\n if (schema) {\n acc[key] = schema;\n }\n return acc;\n }, {} as Record<string, IJsonSchema>),\n };\n }\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport z from 'zod';\n\n// Shared extra schema for flow value types\nexport const extraSchema = z\n .object({\n index: z.number().optional(),\n })\n .optional();\n\nexport const constantSchema = z.object({\n type: z.literal('constant'),\n content: z.any().optional(),\n schema: z.any().optional(),\n extra: extraSchema,\n});\n\nexport const refSchema = z.object({\n type: z.literal('ref'),\n content: z.array(z.string()).optional(),\n extra: extraSchema,\n});\n\nexport const expressionSchema = z.object({\n type: z.literal('expression'),\n content: z.string().optional(),\n extra: extraSchema,\n});\n\nexport const templateSchema = z.object({\n type: z.literal('template'),\n content: z.string().optional(),\n extra: extraSchema,\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport * as ReactDOM from 'react-dom';\n\nexport interface IPolyfillRoot {\n render(children: React.ReactNode): void;\n unmount(): void;\n}\n\n/**\n * React 18 polyfill\n * @param dom\n * @returns\n */\nlet unstableCreateRoot = (dom: HTMLElement): IPolyfillRoot => ({\n render(children: JSX.Element) {\n ReactDOM.render(children, dom);\n },\n unmount() {\n ReactDOM.unmountComponentAtNode(dom);\n },\n});\n\nexport function polyfillCreateRoot(dom: HTMLElement): IPolyfillRoot {\n return unstableCreateRoot(dom);\n}\n\nexport function unstableSetCreateRoot(createRoot: (dom: HTMLElement) => IPolyfillRoot) {\n unstableCreateRoot = createRoot;\n}\n"],"mappings":";AAKA,SAAS,gBAAgB;AAyClB,SAAS,wBAAwB,OAAiB;AACvD,MAAI,SAAS,KAAK,GAAG;AACnB,QAAI,2BAA2B,KAAK,GAAG;AACrC,aAAO,wBAAwB,KAAK;AAAA,IACtC;AAEA,WAAO,OAAO;AAAA,MACZ,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAKA,MAAK,MAAqB;AAAA,QACzD;AAAA,QACA,wBAAwBA,MAAK;AAAA,MAC/B,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,IAAI,uBAAuB;AAAA,EAC1C;AAEA,SAAO;AACT;AAgCO,SAAS,sBAAsB,OAAiB;AACrD,MAAI,SAAS,KAAK,GAAG;AACnB,QAAI,wBAAwB,KAAK,GAAG;AAClC,aA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B,MAAM;AAAA,MACvC;AAEA,UAAI,MAAM,MAAM,GAAG;AACjB,cAAM,WAAW,MAAM,UAAU,aAAa,QAAQ,OAAO;AAC7D,cAAM,SAAS,UAAU,OAAO,gBAAgB,YAAY,UAAU,IAAI,IAAI;AAE9E,eAAO;AAAA,MACT;AAEA,UAAI,WAAW,MAAM,GAAG;AACtB,eAAO,EAAE,MAAM,SAAS;AAAA,MAC1B;AAEA,aAAO;AAAA,QACL,MAAM;AAAA,QACN,YAAY,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,KAAK,QAAQ;AACnD,gBAAM,SAAS,gBAAiB,OAAe,GAAG,GAAG,KAAK;AAC1D,cAAI,QAAQ;AACV,gBAAI,GAAG,IAAI;AAAA,UACb;AACA,iBAAO;AAAA,QACT,GAAG,CAAC,CAAgC;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AA5BO,EAAAA,gBAAS;AAAA,GAtJD;;;AEhBjB,YAAY,cAAc;AAY1B,IAAI,qBAAqB,CAAC,SAAqC;AAAA,EAC7D,OAAO,UAAuB;AAC5B,IAAS,gBAAO,UAAU,GAAG;AAAA,EAC/B;AAAA,EACA,UAAU;AACR,IAAS,gCAAuB,GAAG;AAAA,EACrC;AACF;AAEO,SAAS,mBAAmB,KAAiC;AAClE,SAAO,mBAAmB,GAAG;AAC/B;AAEO,SAAS,sBAAsB,YAAiD;AACrF,uBAAqB;AACvB;","names":["value","isObject","FlowValueUtils","isObject"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/json-editor-with-variables/editor.tsx","../../src/components/json-editor-with-variables/extensions/variable-tree.tsx","../../src/components/json-editor-with-variables/extensions/variable-tag.tsx","../../src/components/json-editor-with-variables/styles.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React from 'react';\n\nimport { I18n } from '@flowgram.ai/editor';\nimport { transformerCreator } from '@coze-editor/editor/preset-code';\nimport { Text } from '@coze-editor/editor/language-json';\n\nimport { CodeEditor, type CodeEditorPropsType } from '@/components/code-editor';\n\nimport { VariableTree } from './extensions/variable-tree';\nimport { VariableTagInject } from './extensions/variable-tag';\n\ntype Match = { match: string; range: [number, number] };\nfunction findAllMatches(inputString: string, regex: RegExp): Match[] {\n const globalRegex = new RegExp(\n regex,\n regex.flags.includes('g') ? regex.flags : regex.flags + 'g'\n );\n let match;\n const matches: Match[] = [];\n\n while ((match = globalRegex.exec(inputString)) !== null) {\n if (match.index === globalRegex.lastIndex) {\n globalRegex.lastIndex++;\n }\n matches.push({\n match: match[0],\n range: [match.index, match.index + match[0].length],\n });\n }\n\n return matches;\n}\n\nconst transformer = transformerCreator((text: Text) => {\n const originalSource = text.toString();\n const matches = findAllMatches(originalSource, /\\{\\{([^\\}]*)\\}\\}/g);\n\n if (matches.length > 0) {\n matches.forEach(({ range }) => {\n text.replaceRange(range[0], range[1], 'null');\n });\n }\n\n return text;\n});\n\nexport interface JsonEditorWithVariablesProps extends Omit<CodeEditorPropsType, 'languageId'> {}\n\nexport function JsonEditorWithVariables(props: JsonEditorWithVariablesProps) {\n return (\n <CodeEditor\n languageId=\"json\"\n activeLinePlaceholder={I18n.t(\"Press '@' to Select variable\")}\n {...props}\n options={{\n transformer,\n ...(props.options || {}),\n }}\n >\n <VariableTree />\n <VariableTagInject />\n </CodeEditor>\n );\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useEffect, useState } from 'react';\n\nimport { Popover, Tree } from '@douyinfe/semi-ui';\nimport {\n Mention,\n MentionOpenChangeEvent,\n getCurrentMentionReplaceRange,\n useEditor,\n PositionMirror,\n} from '@coze-editor/editor/react';\nimport { EditorAPI } from '@coze-editor/editor/preset-prompt';\n\nimport { useVariableTree } from '@/components/variable-selector';\n\nexport function VariableTree() {\n const [posKey, setPosKey] = useState('');\n const [visible, setVisible] = useState(false);\n const [position, setPosition] = useState(-1);\n const editor = useEditor<EditorAPI>();\n\n function insert(variablePath: string) {\n const range = getCurrentMentionReplaceRange(editor.$view.state);\n\n if (!range) {\n return;\n }\n\n editor.replaceText({\n ...range,\n text: '{{' + variablePath + '}}',\n });\n\n setVisible(false);\n }\n\n function handleOpenChange(e: MentionOpenChangeEvent) {\n setPosition(e.state.selection.main.head);\n setVisible(e.value);\n }\n\n useEffect(() => {\n if (!editor) {\n return;\n }\n }, [editor, visible]);\n\n const treeData = useVariableTree({});\n\n return (\n <>\n <Mention triggerCharacters={['@']} onOpenChange={handleOpenChange} />\n\n <Popover\n visible={visible}\n trigger=\"custom\"\n position=\"topLeft\"\n rePosKey={posKey}\n content={\n <div style={{ width: 300 }}>\n <Tree\n treeData={treeData}\n onSelect={(v) => {\n insert(v);\n }}\n />\n </div>\n }\n >\n {/* PositionMirror allows the Popover to appear at the specified cursor position */}\n <PositionMirror\n position={position}\n // When Doc scroll, update position\n onChange={() => setPosKey(String(Math.random()))}\n />\n </Popover>\n </>\n );\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useLayoutEffect } from 'react';\n\nimport { isEqual, last } from 'lodash';\nimport {\n BaseVariableField,\n Disposable,\n DisposableCollection,\n Scope,\n useCurrentScope,\n} from '@flowgram.ai/editor';\nimport { Popover } from '@douyinfe/semi-ui';\nimport { IconIssueStroked } from '@douyinfe/semi-icons';\nimport { useInjector } from '@coze-editor/editor/react';\nimport {\n Decoration,\n DecorationSet,\n EditorView,\n MatchDecorator,\n ViewPlugin,\n WidgetType,\n} from '@codemirror/view';\n\nimport { IPolyfillRoot, polyfillCreateRoot } from '@/shared';\n\nimport { UIPopoverContent, UIRootTitle, UITag, UIVarName } from '../styles';\n\nclass VariableTagWidget extends WidgetType {\n keyPath?: string[];\n\n toDispose = new DisposableCollection();\n\n scope: Scope;\n\n root: IPolyfillRoot;\n\n constructor({ keyPath, scope }: { keyPath?: string[]; scope: Scope }) {\n super();\n\n this.keyPath = keyPath;\n this.scope = scope;\n }\n\n renderIcon = (icon: string | JSX.Element) => {\n if (typeof icon === 'string') {\n return <img style={{ marginRight: 8 }} width={12} height={12} src={icon} />;\n }\n\n return icon;\n };\n\n renderVariable(v?: BaseVariableField) {\n if (!v) {\n this.root.render(\n <UITag prefixIcon={<IconIssueStroked />} color=\"amber\">\n Unknown\n </UITag>\n );\n return;\n }\n\n const rootField = last(v.parentFields);\n\n const rootTitle = (\n <UIRootTitle>{rootField?.meta.title ? `${rootField.meta.title} -` : ''}</UIRootTitle>\n );\n const rootIcon = this.renderIcon(rootField?.meta.icon);\n\n this.root.render(\n <Popover\n content={\n <UIPopoverContent>\n {rootIcon}\n {rootTitle}\n <UIVarName>{v?.keyPath.slice(1).join('.')}</UIVarName>\n </UIPopoverContent>\n }\n >\n <UITag prefixIcon={rootIcon}>\n {rootTitle}\n <UIVarName>{v?.key}</UIVarName>\n </UITag>\n </Popover>\n );\n }\n\n toDOM(view: EditorView): HTMLElement {\n const dom = document.createElement('span');\n\n this.root = polyfillCreateRoot(dom);\n\n this.toDispose.push(\n Disposable.create(() => {\n this.root.unmount();\n })\n );\n\n this.toDispose.push(\n this.scope.available.trackByKeyPath(\n this.keyPath,\n (v) => {\n this.renderVariable(v);\n },\n { triggerOnInit: false }\n )\n );\n\n this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));\n\n return dom;\n }\n\n eq(other: VariableTagWidget) {\n return isEqual(this.keyPath, other.keyPath);\n }\n\n ignoreEvent(): boolean {\n return false;\n }\n\n destroy(dom: HTMLElement): void {\n this.toDispose.dispose();\n }\n}\n\nexport function VariableTagInject() {\n const injector = useInjector();\n\n const scope = useCurrentScope();\n\n // 基于 {{var}} 的正则进行匹配,匹配后进行自定义渲染\n useLayoutEffect(() => {\n const atMatcher = new MatchDecorator({\n regexp: /\\{\\{([^\\}\\{]+)\\}\\}/g,\n decoration: (match) =>\n Decoration.replace({\n widget: new VariableTagWidget({\n keyPath: match[1]?.split('.') ?? [],\n scope,\n }),\n }),\n });\n\n return injector.inject([\n ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(private view: EditorView) {\n this.decorations = atMatcher.createDeco(view);\n }\n\n update() {\n this.decorations = atMatcher.createDeco(this.view);\n }\n },\n {\n decorations: (p) => p.decorations,\n provide(p) {\n return EditorView.atomicRanges.of(\n (view) => view.plugin(p)?.decorations ?? Decoration.none\n );\n },\n }\n ),\n ]);\n }, [injector]);\n\n return null;\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport styled from 'styled-components';\nimport { Tag } from '@douyinfe/semi-ui';\n\nexport const UIRootTitle = styled.div`\n margin-right: 4px;\n min-width: 20px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: var(--semi-color-text-2);\n`;\n\nexport const UIVarName = styled.div`\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n`;\n\nexport const UITag = styled(Tag)`\n display: inline-flex;\n align-items: center;\n justify-content: flex-start;\n max-width: 300px;\n\n & .semi-tag-content-center {\n justify-content: flex-start;\n }\n\n &.semi-tag {\n margin: 0 5px;\n }\n`;\n\nexport const UIPopoverContent = styled.div`\n padding: 10px;\n display: inline-flex;\n align-items: center;\n justify-content: flex-start;\n`;\n"],"mappings":";;;;;;;;;AAKA,OAAOA,YAAW;AAElB,SAAS,YAAY;AACrB,SAAS,0BAA0B;;;ACHnC,OAAO,SAAS,WAAW,gBAAgB;AAE3C,SAAS,SAAS,YAAY;AAC9B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKA,SAAS,eAAe;AAC7B,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,EAAE;AACvC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,EAAE;AAC3C,QAAM,SAAS,UAAqB;AAEpC,W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;AAAA,MACC,YAAW;AAAA,MACX,uBAAuB,KAAK,EAAE,8BAA8B;AAAA,MAC3D,GAAG;AAAA,MACJ,SAAS;AAAA,QACP;AAAA,QACA,GAAI,MAAM,WAAW,CAAC;AAAA,MACxB;AAAA;AAAA,IAEA,gBAAAA,OAAA,cAAC,kBAAa;AAAA,IACd,gBAAAA,OAAA,cAAC,uBAAkB;AAAA,EACrB;AAEJ;","names":["React","React","Popover","React","Popover","React"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/prompt-editor-with-variables/editor.tsx","../../src/components/prompt-editor-with-variables/extensions/variable-tree.tsx","../../src/components/prompt-editor-with-variables/extensions/variable-tag.tsx","../../src/components/prompt-editor-with-variables/styles.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React from 'react';\n\nimport { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';\n\nimport { VariableTree } from './extensions/variable-tree';\nimport { VariableTagInject } from './extensions/variable-tag';\n\nexport interface PromptEditorWithVariablesProps extends PromptEditorPropsType {}\n\nexport function PromptEditorWithVariables(props: PromptEditorWithVariablesProps) {\n return (\n <PromptEditor {...props}>\n <VariableTree />\n <VariableTagInject />\n </PromptEditor>\n );\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useEffect, useState } from 'react';\n\nimport { Popover, Tree } from '@douyinfe/semi-ui';\nimport {\n Mention,\n MentionOpenChangeEvent,\n getCurrentMentionReplaceRange,\n useEditor,\n PositionMirror,\n} from '@coze-editor/editor/react';\nimport { EditorAPI } from '@coze-editor/editor/preset-prompt';\n\nimport { useVariableTree } from '@/components/variable-selector';\n\nexport function VariableTree() {\n const [posKey, setPosKey] = useState('');\n const [visible, setVisible] = useState(false);\n const [position, setPosition] = useState(-1);\n const editor = useEditor<EditorAPI>();\n\n function insert(variablePath: string) {\n const range = getCurrentMentionReplaceRange(editor.$view.state);\n\n if (!range) {\n return;\n }\n\n /**\n * When user input {{xxxx}}, {{{xxx}}}(more brackets if possible), replace all brackets with {{xxxx}}\n */\n let { from, to } = range;\n while (editor.$view.state.doc.sliceString(from - 1, from) === '{') {\n from--;\n }\n while (editor.$view.state.doc.sliceString(to, to + 1) === '}') {\n to++;\n }\n\n editor.replaceText({\n from,\n to,\n text: '{{' + variablePath + '}}',\n });\n\n setVisible(false);\n }\n\n function handleOpenChange(e: MentionOpenChangeEvent) {\n setPosition(e.state.selection.main.head);\n setVisible(e.value);\n }\n\n useEffect(() => {\n if (!editor) {\n return;\n }\n }, [editor, visible]);\n\n const treeData = useVariableTree({});\n\n return (\n <>\n <Mention triggerCharacters={['{', '{}', '@']} onOpenChange={handleOpenChange} />\n\n <Popover\n visible={visible}\n trigger=\"custom\"\n position=\"topLeft\"\n rePosKey={posKey}\n content={\n <div style={{ width: 300 }}>\n <Tree\n treeData={treeData}\n onSelect={(v) => {\n insert(v);\n }}\n />\n </div>\n }\n >\n {/* PositionMirror allows the Popover to appear at the specified cursor position */}\n <PositionMirror\n position={position}\n // When Doc scroll, update position\n onChange={() => setPosKey(String(Math.random()))}\n />\n </Popover>\n </>\n );\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useLayoutEffect } from 'react';\n\nimport { isEqual, last } from 'lodash';\nimport {\n BaseVariableField,\n Disposable,\n DisposableCollection,\n Scope,\n useCurrentScope,\n} from '@flowgram.ai/editor';\nimport { Popover } from '@douyinfe/semi-ui';\nimport { IconIssueStroked } from '@douyinfe/semi-icons';\nimport { useInjector } from '@coze-editor/editor/react';\nimport {\n Decoration,\n DecorationSet,\n EditorView,\n MatchDecorator,\n ViewPlugin,\n WidgetType,\n} from '@codemirror/view';\n\nimport { IPolyfillRoot, polyfillCreateRoot } from '@/shared';\n\nimport { UIPopoverContent, UIRootTitle, UITag, UIVarName } from '../styles';\n\nclass VariableTagWidget extends WidgetType {\n keyPath?: string[];\n\n toDispose = new DisposableCollection();\n\n scope: Scope;\n\n root: IPolyfillRoot;\n\n constructor({ keyPath, scope }: { keyPath?: string[]; scope: Scope }) {\n super();\n\n this.keyPath = keyPath;\n this.scope = scope;\n }\n\n renderIcon = (icon: string | JSX.Element) => {\n if (typeof icon === 'string') {\n return <img style={{ marginRight: 8 }} width={12} height={12} src={icon} />;\n }\n\n return icon;\n };\n\n renderVariable(v?: BaseVariableField) {\n if (!v) {\n this.root.render(\n <UITag prefixIcon={<IconIssueStroked />} color=\"amber\">\n Unknown\n </UITag>\n );\n return;\n }\n\n const rootField = last(v.parentFields);\n\n const rootTitle = (\n <UIRootTitle>{rootField?.meta.title ? `${rootField.meta.title} -` : ''}</UIRootTitle>\n );\n const rootIcon = this.renderIcon(rootField?.meta.icon);\n\n this.root.render(\n <Popover\n content={\n <UIPopoverContent>\n {rootIcon}\n {rootTitle}\n <UIVarName>{v?.keyPath.slice(1).join('.')}</UIVarName>\n </UIPopoverContent>\n }\n >\n <UITag prefixIcon={rootIcon}>\n {rootTitle}\n <UIVarName>{v?.key}</UIVarName>\n </UITag>\n </Popover>\n );\n }\n\n toDOM(view: EditorView): HTMLElement {\n const dom = document.createElement('span');\n\n this.root = polyfillCreateRoot(dom);\n\n this.toDispose.push(\n Disposable.create(() => {\n this.root.unmount();\n })\n );\n\n this.toDispose.push(\n this.scope.available.trackByKeyPath(\n this.keyPath,\n (v) => {\n this.renderVariable(v);\n },\n { triggerOnInit: false }\n )\n );\n\n this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));\n\n return dom;\n }\n\n eq(other: VariableTagWidget) {\n return isEqual(this.keyPath, other.keyPath);\n }\n\n ignoreEvent(): boolean {\n return false;\n }\n\n destroy(dom: HTMLElement): void {\n this.toDispose.dispose();\n }\n}\n\nexport function VariableTagInject() {\n const injector = useInjector();\n\n const scope = useCurrentScope();\n\n // 基于 {{var}} 的正则进行匹配,匹配后进行自定义渲染\n useLayoutEffect(() => {\n const atMatcher = new MatchDecorator({\n regexp: /\\{\\{([^\\}\\{]+)\\}\\}/g,\n decoration: (match) =>\n Decoration.replace({\n widget: new VariableTagWidget({\n keyPath: match[1]?.split('.') ?? [],\n scope,\n }),\n }),\n });\n\n return injector.inject([\n ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(private view: EditorView) {\n this.decorations = atMatcher.createDeco(view);\n }\n\n update() {\n this.decorations = atMatcher.createDeco(this.view);\n }\n },\n {\n decorations: (p) => p.decorations,\n provide(p) {\n return EditorView.atomicRanges.of(\n (view) => view.plugin(p)?.decorations ?? Decoration.none\n );\n },\n }\n ),\n ]);\n }, [injector]);\n\n return null;\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport styled from 'styled-components';\nimport { Tag } from '@douyinfe/semi-ui';\n\nexport const UIRootTitle = styled.div`\n margin-right: 4px;\n min-width: 20px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: var(--semi-color-text-2);\n`;\n\nexport const UIVarName = styled.div`\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n`;\n\nexport const UITag = styled(Tag)`\n display: inline-flex;\n align-items: center;\n justify-content: flex-start;\n max-width: 300px;\n\n & .semi-tag-content-center {\n justify-content: flex-start;\n }\n\n &.semi-tag {\n margin: 0 5px;\n }\n`;\n\nexport const UIPopoverContent = styled.div`\n padding: 10px;\n display: inline-flex;\n align-items: center;\n justify-content: flex-start;\n`;\n"],"mappings":";;;;;;;;;;;AAKA,OAAOA,YAAW;;;ACAlB,OAAO,SAAS,WAAW,gBAAgB;AAE3C,SAAS,SAAS,YAAY;AAC9B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKA,SAAS,eAAe;AAC7B,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,EAAE;AACvC,QAAM,CAAC,SAAS,U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AAY,IAAI,eAAe;AAAA,MACnC,QAAQ;AAAA,MACR,YAAY,CAAC,UACX,WAAW,QAAQ;AAAA,QACjB,QAAQ,IAAI,kBAAkB;AAAA,UAC5B,SAAS,MAAM,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC;AAAA,UAClC;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACL,CAAC;AAED,WAAO,SAAS,OAAO;AAAA,MACrB,WAAW;AAAA,QACT,MAAM;AAAA,UAGJ,YAAoB,MAAkB;AAAlB;AAClB,iBAAK,cAAc,UAAU,WAAW,IAAI;AAAA,UAC9C;AAAA,UAEA,SAAS;AACP,iBAAK,cAAc,UAAU,WAAW,KAAK,IAAI;AAAA,UACnD;AAAA,QACF;AAAA,QACA;AAAA,UACE,aAAa,CAAC,MAAM,EAAE;AAAA,UACtB,QAAQ,GAAG;AACT,mBAAO,WAAW,aAAa;AAAA,cAC7B,CAAC,SAAS,KAAK,OAAO,CAAC,GAAG,eAAe,WAAW;AAAA,YACtD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;;;AF/JO,SAAS,0BAA0B,OAAuC;AAC/E,SACE,gBAAAE,OAAA,cAAC,gBAAc,GAAG,SAChB,gBAAAA,OAAA,cAAC,kBAAa,GACd,gBAAAA,OAAA,cAAC,uBAAkB,CACrB;AAEJ;","names":["React","React","Popover","React","Popover","React"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/prompt-editor-with-inputs/editor.tsx","../../src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx","../../src/components/prompt-editor-with-inputs/inputs-picker.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React from 'react';\n\nimport { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';\n\nimport { InputsTree } from './extensions/inputs-tree';\n\nexport interface PromptEditorWithInputsProps extends PromptEditorPropsType {\n inputsValues: any;\n}\n\nexport function PromptEditorWithInputs({\n inputsValues,\n ...restProps\n}: PromptEditorWithInputsProps) {\n return (\n <PromptEditor {...restProps}>\n <InputsTree inputsValues={inputsValues} />\n </PromptEditor>\n );\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useEffect, useState } from 'react';\n\nimport { Popover } from '@douyinfe/semi-ui';\nimport {\n Mention,\n MentionOpenChangeEvent,\n getCurrentMentionReplaceRange,\n useEditor,\n PositionMirror,\n} from '@coze-editor/editor/react';\nimport { EditorAPI } from '@coze-editor/editor/preset-prompt';\n\nimport { IFlowValue } from '@/typings';\n\nimport { InputsPicker } from '../inputs-picker';\n\nexport function InputsTree({ inputsValues }: { inputsValues: Record<string, IFlowValue> }) {\n const [posKey, setPosKey] = useState('');\n const [visible, setVisible] = useState(false);\n const [position, setPosition] = useState(-1);\n const editor = useEditor<EditorAPI>();\n\n function insert(variablePath: string) {\n const range = getCurrentMentionReplaceRange(editor.$view.state);\n\n if (!range) {\n return;\n }\n\n /**\n * When user input {{xxxx}}, {{{xxx}}}(more brackets if possible), replace all brackets with {{xxxx}}\n */\n let { from, to } = range;\n while (editor.$view.state.doc.sliceString(from - 1, from) === '{') {\n from--;\n }\n while (editor.$view.state.doc.sliceString(to, to + 1) === '}') {\n to++;\n }\n\n editor.replaceText({\n ...range,\n text: '{{' + variablePath + '}}',\n });\n\n setVisible(false);\n }\n\n function handleOpenChange(e: MentionOpenChangeEvent) {\n setPosition(e.state.selection.main.head);\n setVisible(e.value);\n }\n\n useEffect(() => {\n if (!editor) {\n return;\n }\n }, [editor, visible]);\n\n return (\n <>\n <Mention triggerCharacters={['{', '{}', '@']} onOpenChange={handleOpenChange} />\n\n <Popover\n visible={visible}\n trigger=\"custom\"\n position=\"topLeft\"\n rePosKey={posKey}\n content={\n <div style={{ width: 300 }}>\n <InputsPicker\n inputsValues={inputsValues}\n onSelect={(v) => {\n insert(v);\n }}\n />\n </div>\n }\n >\n {/* PositionMirror allows the Popover to appear at the specified cursor position */}\n <PositionMirror\n position={position}\n // When Doc scroll, update position\n onChange={() => setPosKey(String(Math.random()))}\n />\n </Popover>\n </>\n );\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 { isPlainObject, last } from 'lodash';\nimport {\n type ArrayType,\n ASTMatch,\n type BaseType,\n type BaseVariableField,\n useScopeAvailable,\n} from '@flowgram.ai/editor';\nimport { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';\nimport { Tree } from '@douyinfe/semi-ui';\n\nimport { FlowValueUtils } from '@/shared';\n\ntype VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;\n\nexport function InputsPicker({\n inputsValues,\n onSelect,\n}: {\n inputsValues: any;\n onSelect: (v: string) => void;\n}) {\n const available = useScopeAvailable();\n\n const getArrayDrilldown = (type: ArrayType, depth = 1): { type: BaseType; depth: number } => {\n if (ASTMatch.isArray(type.items)) {\n return getArrayDrilldown(type.items, depth + 1);\n }\n\n return { type: type.items, depth: depth };\n };\n\n const renderVariable = (variable: VariableField, keyPath: string[]): TreeNodeData => {\n let type = variable?.type;\n\n let children: TreeNodeData[] | undefined;\n\n if (ASTMatch.isObject(type)) {\n children = (type.properties || [])\n .map((_property) => renderVariable(_property as VariableField, [...keyPath, _property.key]))\n .filter(Boolean) as TreeNodeData[];\n }\n\n if (ASTMatch.isArray(type)) {\n const drilldown = getArrayDrilldown(type);\n\n if (ASTMatch.isObject(drilldown.type)) {\n children = (drilldown.type.properties || [])\n .map((_property) =>\n renderVariable(_property as VariableField, [\n ...keyPath,\n ...new Array(drilldown.depth).fill('[0]'),\n _property.key,\n ])\n )\n .filter(Boolean) as TreeNodeData[];\n }\n }\n\n const key = keyPath\n .map((_key, idx) => (_key === '[0]' || idx === 0 ? _key : `.${_key}`))\n .join('');\n\n return {\n key: key,\n label: last(keyPath),\n value: key,\n children,\n };\n };\n\n const getTreeData = (value: any, keyPath: string[]): TreeNodeData | undefined => {\n const currKey = keyPath.join('.');\n\n if (FlowValueUtils.isFlowValue(value)) {\n if (FlowValueUtils.isRef(value)) {\n const variable = available.getByKeyPath(value.content || []);\n if (variable) {\n return renderVariable(variable, keyPath);\n }\n }\n return {\n key: currKey,\n value: currKey,\n label: last(keyPath),\n };\n }\n\n if (isPlainObject(value)) {\n return {\n key: currKey,\n value: currKey,\n label: last(keyPath),\n children: Object.entries(value)\n .map(([key, value]) => getTreeData(value, [...keyPath, key])!)\n .filter(Boolean),\n };\n }\n };\n\n const treeData: TreeNodeData[] = useMemo(\n () =>\n Object.entries(inputsValues)\n .map(([key, value]) => getTreeData(value, [key])!)\n .filter(Boolean),\n []\n );\n\n return <Tree treeData={treeData} onSelect={(v) => onSelect(v)} />;\n}\n"],"mappings":";;;;;;;;AAKA,OAAOA,YAAW;;;ACAlB,OAAOC,UAAS,WAAW,gBAAgB;AAE3C,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACTP,OAAO,SAAS,eAAe;AAE/B,SAAS,eAAe,YAAY;AACpC;AAAA,EAEE;AAAA,EAGA;AAAA,OACK;AAEP,SAAS,YAAY;AAMd,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGG;AACD,QAAM,YAAY,kBAAkB;AAEpC,QAAM,oBAAoB,CAAC,MAAiB,QAAQ,MAAyC;AAC3F,QAAI,SAAS,QAAQ,KAAK,KAAK,GAAG;AAChC,aAAO,kBAAkB,KAAK,OAAO,QAAQ,CAAC;AAAA,IAChD;AAEA,WAAO,EAAE,MAAM,KAAK,OAAO,MAAa;AAAA,EAC1C;AAEA,QAAM,iBAAiB,CAAC,UAAyB,YAAoC;AACnF,QAAI,OAAO,UAAU;AAErB,QAAI;AAEJ,QAAI,SAAS,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