@flowgram-vue/form-materials 0.2.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.
Files changed (177) hide show
  1. package/LICENSE +22 -0
  2. package/bin/run.sh +7 -0
  3. package/dist/index.cjs +0 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +0 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +86 -0
  9. package/src/components/assign-row/assign-row.vue +69 -0
  10. package/src/components/assign-row/index.ts +7 -0
  11. package/src/components/assign-row/types.ts +25 -0
  12. package/src/components/assign-rows/assign-rows.vue +44 -0
  13. package/src/components/assign-rows/index.ts +6 -0
  14. package/src/components/batch-outputs/batch-outputs.vue +46 -0
  15. package/src/components/batch-outputs/index.ts +6 -0
  16. package/src/components/batch-outputs/styles.css +17 -0
  17. package/src/components/batch-outputs/types.ts +23 -0
  18. package/src/components/batch-variable-selector/batch-variable-selector.vue +24 -0
  19. package/src/components/batch-variable-selector/index.ts +6 -0
  20. package/src/components/blur-input/blur-input.vue +47 -0
  21. package/src/components/blur-input/index.ts +6 -0
  22. package/src/components/code-editor/base-code-editor.vue +44 -0
  23. package/src/components/code-editor/index.ts +58 -0
  24. package/src/components/code-editor/styles.css +27 -0
  25. package/src/components/code-editor/types.ts +20 -0
  26. package/src/components/code-editor/utils.ts +24 -0
  27. package/src/components/code-editor-mini/code-editor-mini.vue +16 -0
  28. package/src/components/code-editor-mini/index.ts +6 -0
  29. package/src/components/condition-context/context.ts +45 -0
  30. package/src/components/condition-context/hooks/use-condition.ts +120 -0
  31. package/src/components/condition-context/index.ts +14 -0
  32. package/src/components/condition-context/op.ts +86 -0
  33. package/src/components/condition-context/types.ts +22 -0
  34. package/src/components/condition-row/condition-row.vue +126 -0
  35. package/src/components/condition-row/index.ts +7 -0
  36. package/src/components/condition-row/styles.css +30 -0
  37. package/src/components/condition-row/types.ts +12 -0
  38. package/src/components/constant-input/constant-input.vue +48 -0
  39. package/src/components/constant-input/index.ts +7 -0
  40. package/src/components/constant-input/types.ts +23 -0
  41. package/src/components/coze-editor-extensions/extensions/inputs-tree.vue +16 -0
  42. package/src/components/coze-editor-extensions/extensions/variable-tag.vue +10 -0
  43. package/src/components/coze-editor-extensions/extensions/variable-tree.vue +18 -0
  44. package/src/components/coze-editor-extensions/index.ts +22 -0
  45. package/src/components/coze-editor-extensions/styles.css +41 -0
  46. package/src/components/db-condition-row/db-condition-row.vue +112 -0
  47. package/src/components/db-condition-row/index.ts +7 -0
  48. package/src/components/db-condition-row/styles.css +41 -0
  49. package/src/components/db-condition-row/types.ts +20 -0
  50. package/src/components/display-flow-value/display-flow-value.vue +46 -0
  51. package/src/components/display-flow-value/index.ts +6 -0
  52. package/src/components/display-inputs-values/display-inputs-value-all-in-tag.vue +26 -0
  53. package/src/components/display-inputs-values/display-inputs-values.vue +43 -0
  54. package/src/components/display-inputs-values/index.ts +7 -0
  55. package/src/components/display-inputs-values/styles.css +10 -0
  56. package/src/components/display-outputs/display-outputs.vue +62 -0
  57. package/src/components/display-outputs/index.ts +6 -0
  58. package/src/components/display-outputs/styles.css +10 -0
  59. package/src/components/display-schema-tag/display-schema-tag.vue +41 -0
  60. package/src/components/display-schema-tag/index.ts +6 -0
  61. package/src/components/display-schema-tag/styles.css +25 -0
  62. package/src/components/display-schema-tree/display-schema-tree.vue +55 -0
  63. package/src/components/display-schema-tree/index.ts +6 -0
  64. package/src/components/display-schema-tree/styles.css +84 -0
  65. package/src/components/dynamic-value-input/dynamic-value-input.vue +145 -0
  66. package/src/components/dynamic-value-input/hooks.ts +71 -0
  67. package/src/components/dynamic-value-input/index.ts +10 -0
  68. package/src/components/dynamic-value-input/styles.css +59 -0
  69. package/src/components/index.ts +84 -0
  70. package/src/components/inputs-values/index.ts +6 -0
  71. package/src/components/inputs-values/inputs-values.vue +67 -0
  72. package/src/components/inputs-values/styles.css +17 -0
  73. package/src/components/inputs-values/types.ts +23 -0
  74. package/src/components/inputs-values-tree/hooks/use-child-list.ts +65 -0
  75. package/src/components/inputs-values-tree/index.ts +6 -0
  76. package/src/components/inputs-values-tree/inputs-values-tree.vue +59 -0
  77. package/src/components/inputs-values-tree/row.vue +139 -0
  78. package/src/components/inputs-values-tree/styles.css +94 -0
  79. package/src/components/inputs-values-tree/types.ts +23 -0
  80. package/src/components/json-editor-with-variables/index.ts +7 -0
  81. package/src/components/json-editor-with-variables/json-editor-with-variables.vue +24 -0
  82. package/src/components/json-editor-with-variables/types.ts +8 -0
  83. package/src/components/json-schema-creator/index.ts +7 -0
  84. package/src/components/json-schema-creator/json-input-modal.vue +51 -0
  85. package/src/components/json-schema-creator/json-schema-creator.vue +27 -0
  86. package/src/components/json-schema-creator/types.ts +10 -0
  87. package/src/components/json-schema-creator/utils/json-to-schema.ts +50 -0
  88. package/src/components/json-schema-editor/default-value.vue +30 -0
  89. package/src/components/json-schema-editor/hooks.ts +134 -0
  90. package/src/components/json-schema-editor/index.ts +6 -0
  91. package/src/components/json-schema-editor/json-schema-editor.vue +53 -0
  92. package/src/components/json-schema-editor/property-edit.vue +222 -0
  93. package/src/components/json-schema-editor/styles.css +135 -0
  94. package/src/components/json-schema-editor/types.ts +25 -0
  95. package/src/components/prompt-editor/index.ts +7 -0
  96. package/src/components/prompt-editor/prompt-editor.vue +40 -0
  97. package/src/components/prompt-editor/styles.css +14 -0
  98. package/src/components/prompt-editor/types.ts +20 -0
  99. package/src/components/prompt-editor-with-inputs/index.ts +7 -0
  100. package/src/components/prompt-editor-with-inputs/prompt-editor-with-inputs.vue +18 -0
  101. package/src/components/prompt-editor-with-inputs/types.ts +11 -0
  102. package/src/components/prompt-editor-with-variables/index.ts +7 -0
  103. package/src/components/prompt-editor-with-variables/prompt-editor-with-variables.vue +19 -0
  104. package/src/components/prompt-editor-with-variables/types.ts +8 -0
  105. package/src/components/sql-editor-with-variables/index.ts +7 -0
  106. package/src/components/sql-editor-with-variables/sql-editor-with-variables.vue +24 -0
  107. package/src/components/sql-editor-with-variables/types.ts +8 -0
  108. package/src/components/type-selector/index.ts +11 -0
  109. package/src/components/type-selector/type-selector.vue +79 -0
  110. package/src/components/type-selector/types.ts +33 -0
  111. package/src/components/variable-selector/context.ts +44 -0
  112. package/src/components/variable-selector/index.ts +13 -0
  113. package/src/components/variable-selector/styles.css +70 -0
  114. package/src/components/variable-selector/types.ts +22 -0
  115. package/src/components/variable-selector/use-variable-tree.ts +108 -0
  116. package/src/components/variable-selector/variable-selector.vue +139 -0
  117. package/src/effects/auto-rename-ref/index.ts +109 -0
  118. package/src/effects/index.ts +12 -0
  119. package/src/effects/listen-ref-schema-change/index.ts +56 -0
  120. package/src/effects/listen-ref-value-change/index.ts +53 -0
  121. package/src/effects/provide-batch-input/index.ts +40 -0
  122. package/src/effects/provide-json-schema-outputs/index.ts +23 -0
  123. package/src/effects/sync-variable-title/index.ts +25 -0
  124. package/src/effects/validate-when-variable-sync/index.ts +34 -0
  125. package/src/env.d.ts +12 -0
  126. package/src/form-plugins/batch-outputs-plugin/index.ts +120 -0
  127. package/src/form-plugins/index.ts +8 -0
  128. package/src/form-plugins/infer-assign-plugin/index.ts +87 -0
  129. package/src/form-plugins/infer-inputs-plugin/index.ts +85 -0
  130. package/src/hooks/index.ts +6 -0
  131. package/src/hooks/use-object-list/index.ts +161 -0
  132. package/src/index.ts +125 -0
  133. package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +27 -0
  134. package/src/plugins/disable-declaration-plugin/index.ts +6 -0
  135. package/src/plugins/index.ts +16 -0
  136. package/src/plugins/json-schema-preset/create-type-preset-plugin.ts +35 -0
  137. package/src/plugins/json-schema-preset/index.ts +25 -0
  138. package/src/plugins/json-schema-preset/type-definition/array.ts +38 -0
  139. package/src/plugins/json-schema-preset/type-definition/boolean.ts +47 -0
  140. package/src/plugins/json-schema-preset/type-definition/date-time.ts +60 -0
  141. package/src/plugins/json-schema-preset/type-definition/enum.ts +31 -0
  142. package/src/plugins/json-schema-preset/type-definition/index.ts +37 -0
  143. package/src/plugins/json-schema-preset/type-definition/integer.ts +47 -0
  144. package/src/plugins/json-schema-preset/type-definition/map.ts +34 -0
  145. package/src/plugins/json-schema-preset/type-definition/number.ts +46 -0
  146. package/src/plugins/json-schema-preset/type-definition/object.ts +34 -0
  147. package/src/plugins/json-schema-preset/type-definition/string.ts +52 -0
  148. package/src/plugins/json-schema-preset/types.ts +25 -0
  149. package/src/plugins/json-schema-preset/vue.ts +38 -0
  150. package/src/shared/flow-value/index.ts +17 -0
  151. package/src/shared/flow-value/schema.ts +38 -0
  152. package/src/shared/flow-value/types.ts +49 -0
  153. package/src/shared/flow-value/utils.ts +213 -0
  154. package/src/shared/format-legacy-refs/index.ts +158 -0
  155. package/src/shared/format-legacy-refs/readme.md +38 -0
  156. package/src/shared/index.ts +32 -0
  157. package/src/shared/inject-material/index.ts +50 -0
  158. package/src/shared/lazy-suspense/index.ts +20 -0
  159. package/src/shared/polyfill-create-root/index.ts +38 -0
  160. package/src/ui/fg-button.vue +27 -0
  161. package/src/ui/fg-cascader.vue +92 -0
  162. package/src/ui/fg-checkbox.vue +25 -0
  163. package/src/ui/fg-icon-button.vue +31 -0
  164. package/src/ui/fg-input.vue +50 -0
  165. package/src/ui/fg-modal.vue +37 -0
  166. package/src/ui/fg-popover.vue +19 -0
  167. package/src/ui/fg-select.vue +81 -0
  168. package/src/ui/fg-tag.vue +37 -0
  169. package/src/ui/fg-textarea.vue +42 -0
  170. package/src/ui/fg-tree-nodes.vue +48 -0
  171. package/src/ui/fg-tree-select.vue +86 -0
  172. package/src/ui/icons.ts +60 -0
  173. package/src/ui/index.ts +20 -0
  174. package/src/ui/styles.css +277 -0
  175. package/src/ui/types.ts +36 -0
  176. package/src/validate/index.ts +6 -0
  177. package/src/validate/validate-flow-value/index.ts +62 -0
@@ -0,0 +1,139 @@
1
+ <script lang="ts">
2
+ /**
3
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ export default { name: 'InputValueRow' };
7
+ </script>
8
+
9
+ <script setup lang="ts">
10
+ import { computed, defineComponent, h, ref } from 'vue';
11
+ import { I18n } from '@flowgram-vue/i18n';
12
+
13
+ import { IFlowConstantValue } from '@/shared';
14
+ import { ConstantInputStrategy } from '@/components/constant-input';
15
+ import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
16
+ import { BlurInput } from '@/components/blur-input';
17
+ import { FgIconButton, FgInput, IconAddChildren, IconChevronDown, IconChevronRight, IconDelete } from '@/ui';
18
+
19
+ import type { PropsType } from './types';
20
+ import { useChildList } from './hooks/use-child-list';
21
+ import './styles.css';
22
+
23
+ const AddObjectChildStrategy: ConstantInputStrategy = {
24
+ hit: (schema) => schema.type === 'object',
25
+ Renderer: defineComponent({
26
+ name: 'AddObjectChildStrategy',
27
+ setup() {
28
+ return () =>
29
+ h(FgInput, {
30
+ disabled: true,
31
+ style: { pointerEvents: 'none' },
32
+ value: I18n.t('Configure via child fields'),
33
+ });
34
+ },
35
+ }),
36
+ };
37
+
38
+ const props = defineProps<
39
+ {
40
+ keyName?: string;
41
+ value?: any;
42
+ onUpdateKey: (key: string) => void;
43
+ onUpdateValue: (value: any) => void;
44
+ onRemove?: () => void;
45
+ $isLast?: boolean;
46
+ $level?: number;
47
+ } & Pick<PropsType, 'constantProps' | 'hasError' | 'readonly'>
48
+ >();
49
+
50
+ const collapse = ref(false);
51
+ const { canAddField, hasChildren, list, add, updateKey, updateValue, remove } = useChildList(
52
+ props.value,
53
+ props.onUpdateValue
54
+ );
55
+
56
+ const strategies = computed(() => [
57
+ ...(hasChildren.value ? [AddObjectChildStrategy] : []),
58
+ ...(props.constantProps?.strategies || []),
59
+ ]);
60
+
61
+ const flowDisplayValue = computed(() =>
62
+ hasChildren.value
63
+ ? ({
64
+ type: 'constant',
65
+ schema: { type: 'object' },
66
+ } as IFlowConstantValue)
67
+ : props.value
68
+ );
69
+ </script>
70
+
71
+ <template>
72
+ <div
73
+ :class="`gedit-m-inputs-values-tree-tree-item-left ${($level || 0) > 0 ? 'show-line' : ''} ${
74
+ $isLast ? 'is-last' : ''
75
+ } ${hasChildren ? 'show-collapse' : ''}`"
76
+ >
77
+ <div
78
+ v-if="hasChildren"
79
+ class="gedit-m-inputs-values-tree-collapse-trigger"
80
+ @click="collapse = !collapse"
81
+ >
82
+ <IconChevronDown v-if="collapse" />
83
+ <IconChevronRight v-else />
84
+ </div>
85
+ </div>
86
+ <div class="gedit-m-inputs-values-tree-tree-item-right">
87
+ <div class="gedit-m-inputs-values-tree-tree-item-main">
88
+ <div class="gedit-m-inputs-values-tree-row">
89
+ <BlurInput
90
+ :style="{ width: '100px', minWidth: '100px', maxWidth: '100px' }"
91
+ :disabled="readonly"
92
+ :value="keyName"
93
+ :placeholder="I18n.t('Input Key')"
94
+ @change="(v) => onUpdateKey?.(v)"
95
+ />
96
+ <InjectDynamicValueInput
97
+ :style="{ flexGrow: 1 }"
98
+ :readonly="readonly"
99
+ :value="flowDisplayValue"
100
+ :has-error="hasError"
101
+ :constant-props="{ ...constantProps, strategies }"
102
+ :on-change="(v) => onUpdateValue(v)"
103
+ />
104
+ <div class="gedit-m-inputs-values-tree-actions">
105
+ <FgIconButton
106
+ v-if="canAddField"
107
+ :disabled="readonly"
108
+ :icon="IconAddChildren()"
109
+ @click="
110
+ () => {
111
+ add({ type: 'constant', content: '', schema: { type: 'string' } });
112
+ collapse = true;
113
+ }
114
+ "
115
+ />
116
+ <FgIconButton :disabled="readonly" :icon="IconDelete()" @click="onRemove?.()" />
117
+ </div>
118
+ </div>
119
+ </div>
120
+ <div v-if="hasChildren" :class="`gedit-m-inputs-values-tree-collapsible ${collapse ? 'collapse' : ''}`">
121
+ <div class="gedit-m-inputs-values-tree-tree-items shrink">
122
+ <InputValueRow
123
+ v-for="(_item, index) in list"
124
+ :key="_item.id"
125
+ :readonly="readonly"
126
+ :has-error="hasError"
127
+ :constant-props="constantProps"
128
+ :key-name="_item.key"
129
+ :value="_item.value"
130
+ :$level="($level || 0) + 1"
131
+ :$is-last="index === list.length - 1"
132
+ :on-update-value="(_v) => updateValue(_item.id, _v)"
133
+ :on-update-key="(k) => updateKey(_item.id, k)"
134
+ :on-remove="() => remove(_item.id)"
135
+ />
136
+ </div>
137
+ </div>
138
+ </div>
139
+ </template>
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ .gedit-m-inputs-values-tree-container {
7
+ }
8
+
9
+ .gedit-m-inputs-values-tree-row {
10
+ display: flex;
11
+ align-items: flex-start;
12
+ gap: 5px;
13
+ }
14
+
15
+ .gedit-m-inputs-values-tree-collapse-trigger {
16
+ cursor: pointer;
17
+ margin-right: 5px;
18
+ }
19
+
20
+ .gedit-m-inputs-values-tree-tree-items {
21
+ display: grid;
22
+ grid-template-columns: auto 1fr;
23
+ }
24
+
25
+ .gedit-m-inputs-values-tree-tree-items.shrink {
26
+ padding-left: 3px;
27
+ margin-top: 10px;
28
+ }
29
+
30
+ .gedit-m-inputs-values-tree-tree-item-left {
31
+ grid-column: 1;
32
+ position: relative;
33
+ width: 16px;
34
+ }
35
+
36
+ .gedit-m-inputs-values-tree-tree-item-left.show-line::before {
37
+ /* 竖线 */
38
+ content: "";
39
+ height: var(--line-height, 100%);
40
+ position: absolute;
41
+ left: -14px;
42
+ top: -16px;
43
+ width: 1px;
44
+ background: #d9d9d9;
45
+ display: block;
46
+ }
47
+
48
+ .gedit-m-inputs-values-tree-tree-item-left.show-line::after {
49
+ /* 横线 */
50
+ content: "";
51
+ position: absolute;
52
+ left: -14px; /* 横线起点和竖线对齐 */
53
+ top: 8px; /* 跟随你的行高调整 */
54
+ width: var(--line-width, 30px); /* 横线长度 */
55
+ height: 1px;
56
+ background: #d9d9d9;
57
+ display: block;
58
+ }
59
+
60
+ .gedit-m-inputs-values-tree-tree-item-left.show-line.is-last::before {
61
+ height: 24px;
62
+ }
63
+
64
+ .gedit-m-inputs-values-tree-tree-item-left.show-line.show-collapse::after {
65
+ width: 12px;
66
+ }
67
+
68
+ .gedit-m-inputs-values-tree-tree-item-right {
69
+ grid-column: 2;
70
+ margin-bottom: 10px;
71
+
72
+ &:last-child {
73
+ margin-bottom: 0px;
74
+ }
75
+ }
76
+
77
+ .gedit-m-inputs-values-tree-tree-item-main {
78
+ display: flex;
79
+ flex-direction: column;
80
+ gap: 10px;
81
+ position: relative;
82
+ }
83
+
84
+ .gedit-m-inputs-values-tree-collapsible {
85
+ display: none;
86
+ }
87
+
88
+ .gedit-m-inputs-values-tree-collapsible.collapse {
89
+ display: block;
90
+ }
91
+
92
+ .gedit-m-inputs-values-tree-actions {
93
+ white-space: nowrap;
94
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { IJsonSchema } from '@flowgram-vue/json-schema';
7
+ import type { CSSProperties } from 'vue';
8
+
9
+ import { IInputsValues } from '@/shared';
10
+ import { ConstantInputStrategy } from '@/components/constant-input';
11
+
12
+ export interface PropsType {
13
+ value?: IInputsValues;
14
+ onChange: (value?: IInputsValues) => void;
15
+ readonly?: boolean;
16
+ hasError?: boolean;
17
+ schema?: IJsonSchema;
18
+ style?: CSSProperties;
19
+ constantProps?: {
20
+ strategies?: ConstantInputStrategy[];
21
+ [key: string]: any;
22
+ };
23
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export { default as JsonEditorWithVariables } from './json-editor-with-variables.vue';
7
+ export type { JsonEditorWithVariablesProps } from './types';
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ import { I18n } from '@flowgram-vue/i18n';
8
+
9
+ import { EditorVariableTree, EditorVariableTagInject } from '@/components/coze-editor-extensions';
10
+ import { JsonCodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
11
+ import type { JsonEditorWithVariablesProps } from './types';
12
+
13
+ defineProps<JsonEditorWithVariablesProps>();
14
+ </script>
15
+
16
+ <template>
17
+ <JsonCodeEditor
18
+ :active-line-placeholder="activeLinePlaceholder || I18n.t(`Press '@' to Select variable`)"
19
+ v-bind="$props"
20
+ >
21
+ <EditorVariableTree :trigger-characters="['@']" />
22
+ <EditorVariableTagInject />
23
+ </JsonCodeEditor>
24
+ </template>
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { type CodeEditorPropsType } from '@/components/code-editor';
7
+
8
+ export type JsonEditorWithVariablesProps = Omit<CodeEditorPropsType, 'languageId'>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export { default as JsonSchemaCreator } from './json-schema-creator.vue';
7
+ export type { JsonSchemaCreatorProps } from './types';
@@ -0,0 +1,51 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ import { ref } from 'vue';
8
+ import type { IJsonSchema } from '@flowgram-vue/json-schema';
9
+ import { I18n } from '@flowgram-vue/i18n';
10
+
11
+ import { FgModal } from '@/ui';
12
+ import { JsonCodeEditor } from '@/components/code-editor';
13
+ import { jsonToSchema } from './utils/json-to-schema';
14
+
15
+ const props = defineProps<{
16
+ visible?: boolean;
17
+ onClose: () => void;
18
+ onConfirm: (schema: IJsonSchema) => void;
19
+ }>();
20
+
21
+ const jsonInput = ref('');
22
+ const error = ref('');
23
+
24
+ const handleConfirm = () => {
25
+ try {
26
+ const schema = jsonToSchema(jsonInput.value);
27
+ props.onConfirm(schema);
28
+ jsonInput.value = '';
29
+ error.value = '';
30
+ } catch (err) {
31
+ error.value = (err as Error).message;
32
+ }
33
+ };
34
+ </script>
35
+
36
+ <template>
37
+ <FgModal
38
+ :visible="visible"
39
+ :title="I18n.t('JSON to JSONSchema')"
40
+ :ok-text="I18n.t('Generate')"
41
+ :cancel-text="I18n.t('Cancel')"
42
+ @close="onClose"
43
+ @confirm="handleConfirm"
44
+ >
45
+ <div style="margin-bottom: 8px">{{ I18n.t('Paste JSON data') }}:</div>
46
+ <div style="min-height: 300px">
47
+ <JsonCodeEditor :value="jsonInput" :on-change="(value) => (jsonInput = value || '')" />
48
+ </div>
49
+ <div v-if="error" style="margin-top: 8px; color: #f93920">{{ error }}</div>
50
+ </FgModal>
51
+ </template>
@@ -0,0 +1,27 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ import { ref } from 'vue';
8
+ import type { IJsonSchema } from '@flowgram-vue/json-schema';
9
+ import { I18n } from '@flowgram-vue/i18n';
10
+
11
+ import { FgButton } from '@/ui';
12
+ import JsonInputModal from './json-input-modal.vue';
13
+ import type { JsonSchemaCreatorProps } from './types';
14
+
15
+ const props = defineProps<JsonSchemaCreatorProps>();
16
+ const visible = ref(false);
17
+
18
+ const handleCreate = (schema: IJsonSchema) => {
19
+ props.onSchemaCreate?.(schema);
20
+ visible.value = false;
21
+ };
22
+ </script>
23
+
24
+ <template>
25
+ <FgButton @click="visible = true">{{ I18n.t('JSON to JSONSchema') }}</FgButton>
26
+ <JsonInputModal :visible="visible" :on-close="() => (visible = false)" :on-confirm="handleCreate" />
27
+ </template>
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import type { IJsonSchema } from '@flowgram-vue/json-schema';
7
+
8
+ export interface JsonSchemaCreatorProps {
9
+ onSchemaCreate?: (schema: IJsonSchema) => void;
10
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import type { IJsonSchema } from '@flowgram-vue/json-schema';
7
+
8
+ export function jsonToSchema(jsonString: string): IJsonSchema {
9
+ // 1. 解析 JSON
10
+ const data = JSON.parse(jsonString); // 会自动抛出语法错误
11
+
12
+ // 2. 生成 schema
13
+ return generateSchema(data);
14
+ }
15
+
16
+ function generateSchema(value: any): IJsonSchema {
17
+ // null
18
+ if (value === null) {
19
+ return { type: 'string' };
20
+ }
21
+
22
+ // array
23
+ if (Array.isArray(value)) {
24
+ const schema: IJsonSchema = { type: 'array' };
25
+ if (value.length > 0) {
26
+ schema.items = generateSchema(value[0]);
27
+ }
28
+ return schema;
29
+ }
30
+
31
+ // object
32
+ if (typeof value === 'object') {
33
+ const schema: IJsonSchema = {
34
+ type: 'object',
35
+ properties: {},
36
+ required: [],
37
+ };
38
+
39
+ for (const [key, val] of Object.entries(value)) {
40
+ schema.properties![key] = generateSchema(val);
41
+ schema.required!.push(key);
42
+ }
43
+
44
+ return schema;
45
+ }
46
+
47
+ // primitive types
48
+ const type = typeof value;
49
+ return { type: type as any };
50
+ }
@@ -0,0 +1,30 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ import { IJsonSchema } from '@flowgram-vue/json-schema';
8
+ import { I18n } from '@flowgram-vue/i18n';
9
+
10
+ import { ConstantInput } from '@/components/constant-input';
11
+
12
+ defineProps<{
13
+ value?: unknown;
14
+ schema?: IJsonSchema;
15
+ placeholder?: string;
16
+ onChange: (value: unknown) => void;
17
+ }>();
18
+ </script>
19
+
20
+ <template>
21
+ <div class="gedit-m-json-schema-editor-constant-input-wrapper">
22
+ <ConstantInput
23
+ :value="value"
24
+ :schema="schema || { type: 'string' }"
25
+ :placeholder="placeholder ?? I18n.t('Default value if parameter is not provided')"
26
+ enable-multi-line-str
27
+ :on-change="onChange"
28
+ />
29
+ </div>
30
+ </template>
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { computed, ref, watch } from 'vue';
7
+ import { difference, omit } from 'lodash-es';
8
+ import { produce } from 'immer';
9
+ import { IJsonSchema, type JsonSchemaTypeManager, useTypeManager } from '@flowgram-vue/json-schema';
10
+
11
+ import { PropertyValueType } from './types';
12
+
13
+ let _id = 0;
14
+ function genId() {
15
+ return _id++;
16
+ }
17
+
18
+ export function usePropertiesEdit(
19
+ value?: PropertyValueType,
20
+ onChange?: (value: PropertyValueType) => void
21
+ ) {
22
+ const typeManager = useTypeManager() as JsonSchemaTypeManager;
23
+ const drilldownSchema = computed(() => typeManager.getPropertiesParent(value || {}));
24
+ const canAddField = computed(() => typeManager.canAddField(value || {}));
25
+ const propertyList = ref<PropertyValueType[]>([]);
26
+ const latestPropertyListRef = ref(propertyList.value);
27
+ const effectVersion = ref(0);
28
+ const changeVersion = ref(0);
29
+
30
+ watch(
31
+ drilldownSchema,
32
+ () => {
33
+ effectVersion.value = effectVersion.value + 1;
34
+ if (effectVersion.value === changeVersion.value) {
35
+ return;
36
+ }
37
+ effectVersion.value = changeVersion.value;
38
+
39
+ const _list = latestPropertyListRef.value;
40
+ const newNames = Object.entries(drilldownSchema.value?.properties || {})
41
+ .sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0))
42
+ .map(([key]) => key);
43
+
44
+ const oldNames = _list.map((item) => item.name).filter(Boolean) as string[];
45
+ const addNames = difference(newNames, oldNames);
46
+
47
+ const next = _list
48
+ .filter((item) => !item.name || newNames.includes(item.name))
49
+ .map((item) => ({
50
+ key: item.key,
51
+ name: item.name,
52
+ isPropertyRequired: drilldownSchema.value?.required?.includes(item.name || '') || false,
53
+ ...(drilldownSchema.value?.properties?.[item.name || ''] || item || {}),
54
+ }))
55
+ .concat(
56
+ addNames.map((_name) => ({
57
+ key: genId(),
58
+ name: _name,
59
+ isPropertyRequired: drilldownSchema.value?.required?.includes(_name) || false,
60
+ ...(drilldownSchema.value?.properties?.[_name] || {}),
61
+ }))
62
+ );
63
+
64
+ latestPropertyListRef.value = next;
65
+ propertyList.value = next;
66
+ },
67
+ { immediate: true }
68
+ );
69
+
70
+ const updatePropertyList = (updater: (list: PropertyValueType[]) => PropertyValueType[]) => {
71
+ changeVersion.value = changeVersion.value + 1;
72
+ const next = updater(latestPropertyListRef.value);
73
+ latestPropertyListRef.value = next;
74
+ propertyList.value = next;
75
+
76
+ const nextProperties: Record<string, IJsonSchema> = {};
77
+ const nextRequired: string[] = [];
78
+
79
+ for (const _property of next) {
80
+ if (!_property.name) {
81
+ continue;
82
+ }
83
+ nextProperties[_property.name] = omit(_property, ['key', 'name', 'isPropertyRequired']);
84
+ if (_property.isPropertyRequired) {
85
+ nextRequired.push(_property.name);
86
+ }
87
+ }
88
+
89
+ onChange?.(
90
+ produce(value || {}, (draft) => {
91
+ const propertiesParent = typeManager.getPropertiesParent(draft);
92
+ if (propertiesParent) {
93
+ propertiesParent.properties = nextProperties;
94
+ propertiesParent.required = nextRequired;
95
+ }
96
+ })
97
+ );
98
+ };
99
+
100
+ const onAddProperty = () => {
101
+ const _list = latestPropertyListRef.value;
102
+ const next = [
103
+ ..._list,
104
+ { key: genId(), name: '', type: 'string', extra: { index: _list.length + 1 } },
105
+ ];
106
+ latestPropertyListRef.value = next;
107
+ propertyList.value = next;
108
+ };
109
+
110
+ const onRemoveProperty = (key: number) => {
111
+ updatePropertyList((_list) => _list.filter((_property) => _property.key !== key));
112
+ };
113
+
114
+ const onEditProperty = (key: number, nextValue: PropertyValueType) => {
115
+ updatePropertyList((_list) =>
116
+ _list.map((_property) => (_property.key === key ? nextValue : _property))
117
+ );
118
+ };
119
+
120
+ watch(canAddField, (next) => {
121
+ if (!next) {
122
+ latestPropertyListRef.value = [];
123
+ propertyList.value = [];
124
+ }
125
+ });
126
+
127
+ return {
128
+ propertyList,
129
+ canAddField,
130
+ onAddProperty,
131
+ onRemoveProperty,
132
+ onEditProperty,
133
+ };
134
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export { default as JsonSchemaEditor } from './json-schema-editor.vue';
@@ -0,0 +1,53 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ import { computed } from 'vue';
8
+ import { IJsonSchema } from '@flowgram-vue/json-schema';
9
+ import { I18n } from '@flowgram-vue/i18n';
10
+
11
+ import { FgButton, IconPlus } from '@/ui';
12
+
13
+ import type { ConfigType } from './types';
14
+ import { usePropertiesEdit } from './hooks';
15
+ import PropertyEdit from './property-edit.vue';
16
+ import './styles.css';
17
+
18
+ const DEFAULT = { type: 'object' };
19
+
20
+ const props = defineProps<{
21
+ value?: IJsonSchema;
22
+ onChange?: (value: IJsonSchema) => void;
23
+ config?: ConfigType;
24
+ className?: string;
25
+ readonly?: boolean;
26
+ }>();
27
+
28
+ const schemaValue = computed(() => props.value || DEFAULT);
29
+ const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
30
+ schemaValue.value,
31
+ props.onChange
32
+ );
33
+ </script>
34
+
35
+ <template>
36
+ <div class="gedit-m-json-schema-editor-container">
37
+ <div class="gedit-m-json-schema-editor-tree-items">
38
+ <PropertyEdit
39
+ v-for="_property in propertyList"
40
+ :key="_property.key"
41
+ :readonly="readonly"
42
+ :value="_property"
43
+ :config="config"
44
+ :on-change="(_v) => onEditProperty(_property.key!, _v)"
45
+ :on-remove="() => onRemoveProperty(_property.key!)"
46
+ />
47
+ </div>
48
+ <FgButton :disabled="readonly" :style="{ marginTop: '10px', marginLeft: '16px' }" @click="onAddProperty">
49
+ <IconPlus />
50
+ {{ config?.addButtonText ?? I18n.t('Add') }}
51
+ </FgButton>
52
+ </div>
53
+ </template>