@flowgram.ai/form-materials 0.1.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/bin/index.ts +99 -0
  2. package/bin/materials.ts +156 -0
  3. package/bin/project.ts +91 -0
  4. package/dist/esm/index.js +3303 -0
  5. package/dist/esm/index.js.map +1 -0
  6. package/dist/index.d.mts +495 -0
  7. package/dist/index.d.ts +495 -0
  8. package/dist/index.js +3299 -0
  9. package/dist/index.js.map +1 -0
  10. package/package.json +75 -0
  11. package/src/components/batch-outputs/config.json +12 -0
  12. package/src/components/batch-outputs/index.tsx +61 -0
  13. package/src/components/batch-outputs/styles.tsx +19 -0
  14. package/src/components/batch-outputs/types.ts +22 -0
  15. package/src/components/batch-outputs/use-list.ts +86 -0
  16. package/src/components/batch-variable-selector/config.json +5 -0
  17. package/src/components/batch-variable-selector/index.tsx +24 -0
  18. package/src/components/code-editor/config.json +9 -0
  19. package/src/components/code-editor/index.tsx +74 -0
  20. package/src/components/code-editor/language-features.ts +24 -0
  21. package/src/components/code-editor/theme/dark.ts +119 -0
  22. package/src/components/code-editor/theme/index.ts +12 -0
  23. package/src/components/code-editor/theme/light.ts +119 -0
  24. package/src/components/code-editor/utils.ts +20 -0
  25. package/src/components/condition-row/config.json +5 -0
  26. package/src/components/condition-row/constants.ts +128 -0
  27. package/src/components/condition-row/hooks/useOp.tsx +50 -0
  28. package/src/components/condition-row/hooks/useRule.ts +31 -0
  29. package/src/components/condition-row/index.tsx +81 -0
  30. package/src/components/condition-row/styles.tsx +30 -0
  31. package/src/components/condition-row/types.ts +42 -0
  32. package/src/components/constant-input/config.json +6 -0
  33. package/src/components/constant-input/index.tsx +86 -0
  34. package/src/components/constant-input/types.ts +23 -0
  35. package/src/components/dynamic-value-input/config.json +5 -0
  36. package/src/components/dynamic-value-input/index.tsx +92 -0
  37. package/src/components/dynamic-value-input/styles.tsx +26 -0
  38. package/src/components/index.ts +18 -0
  39. package/src/components/json-editor-with-variables/config.json +13 -0
  40. package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +173 -0
  41. package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +83 -0
  42. package/src/components/json-editor-with-variables/index.tsx +19 -0
  43. package/src/components/json-editor-with-variables/styles.tsx +44 -0
  44. package/src/components/json-schema-editor/components/blur-input.tsx +27 -0
  45. package/src/components/json-schema-editor/config.json +13 -0
  46. package/src/components/json-schema-editor/default-value.tsx +135 -0
  47. package/src/components/json-schema-editor/hooks.tsx +166 -0
  48. package/src/components/json-schema-editor/index.tsx +267 -0
  49. package/src/components/json-schema-editor/styles.tsx +240 -0
  50. package/src/components/json-schema-editor/types.ts +26 -0
  51. package/src/components/json-schema-editor/utils.ts +29 -0
  52. package/src/components/prompt-editor/config.json +9 -0
  53. package/src/components/prompt-editor/extensions/jinja.tsx +58 -0
  54. package/src/components/prompt-editor/extensions/language-support.tsx +19 -0
  55. package/src/components/prompt-editor/extensions/markdown.tsx +75 -0
  56. package/src/components/prompt-editor/index.tsx +68 -0
  57. package/src/components/prompt-editor/styles.tsx +18 -0
  58. package/src/components/prompt-editor/types.tsx +18 -0
  59. package/src/components/prompt-editor-with-inputs/config.json +13 -0
  60. package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +82 -0
  61. package/src/components/prompt-editor-with-inputs/index.tsx +22 -0
  62. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +100 -0
  63. package/src/components/prompt-editor-with-variables/config.json +13 -0
  64. package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +179 -0
  65. package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +83 -0
  66. package/src/components/prompt-editor-with-variables/index.tsx +19 -0
  67. package/src/components/prompt-editor-with-variables/styles.tsx +44 -0
  68. package/src/components/type-selector/config.json +5 -0
  69. package/src/components/type-selector/constants.tsx +364 -0
  70. package/src/components/type-selector/index.tsx +62 -0
  71. package/src/components/variable-selector/config.json +5 -0
  72. package/src/components/variable-selector/index.tsx +116 -0
  73. package/src/components/variable-selector/styles.tsx +59 -0
  74. package/src/components/variable-selector/use-variable-tree.tsx +103 -0
  75. package/src/effects/auto-rename-ref/config.json +5 -0
  76. package/src/effects/auto-rename-ref/index.ts +109 -0
  77. package/src/effects/index.ts +10 -0
  78. package/src/effects/provide-batch-input/config.json +5 -0
  79. package/src/effects/provide-batch-input/index.ts +43 -0
  80. package/src/effects/provide-batch-outputs/config.json +5 -0
  81. package/src/effects/provide-batch-outputs/index.ts +38 -0
  82. package/src/effects/provide-json-schema-outputs/config.json +8 -0
  83. package/src/effects/provide-json-schema-outputs/index.ts +28 -0
  84. package/src/effects/sync-variable-title/config.json +5 -0
  85. package/src/effects/sync-variable-title/index.ts +28 -0
  86. package/src/form-plugins/batch-outputs-plugin/config.json +7 -0
  87. package/src/form-plugins/batch-outputs-plugin/index.ts +104 -0
  88. package/src/form-plugins/index.ts +6 -0
  89. package/src/index.ts +10 -0
  90. package/src/typings/flow-value/config.json +5 -0
  91. package/src/typings/flow-value/index.ts +32 -0
  92. package/src/typings/index.ts +7 -0
  93. package/src/typings/json-schema/config.json +5 -0
  94. package/src/typings/json-schema/index.ts +36 -0
  95. package/src/utils/format-legacy-refs/config.json +5 -0
  96. package/src/utils/format-legacy-refs/index.ts +158 -0
  97. package/src/utils/format-legacy-refs/readme.md +38 -0
  98. package/src/utils/index.ts +7 -0
  99. package/src/utils/json-schema/config.json +5 -0
  100. package/src/utils/json-schema/index.ts +180 -0
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React, { useMemo, useState } from 'react';
7
+
8
+ import { Button, Checkbox, IconButton } from '@douyinfe/semi-ui';
9
+ import {
10
+ IconExpand,
11
+ IconShrink,
12
+ IconPlus,
13
+ IconChevronDown,
14
+ IconChevronRight,
15
+ IconMinus,
16
+ } from '@douyinfe/semi-icons';
17
+
18
+ import { TypeSelector } from '../type-selector';
19
+ import { IJsonSchema } from '../../typings';
20
+ import { ConfigType, PropertyValueType } from './types';
21
+ import {
22
+ IconAddChildren,
23
+ UIActions,
24
+ UICollapseTrigger,
25
+ UICollapsible,
26
+ UIContainer,
27
+ UIExpandDetail,
28
+ UILabel,
29
+ UIProperties,
30
+ UIPropertyLeft,
31
+ UIPropertyMain,
32
+ UIPropertyRight,
33
+ UIRequired,
34
+ UIType,
35
+ } from './styles';
36
+ import { UIName } from './styles';
37
+ import { DefaultValueWrapper, UIRow } from './styles';
38
+ import { usePropertiesEdit } from './hooks';
39
+ import { DefaultValue } from './default-value';
40
+ import { BlurInput } from './components/blur-input';
41
+
42
+ export function JsonSchemaEditor(props: {
43
+ value?: IJsonSchema;
44
+ onChange?: (value: IJsonSchema) => void;
45
+ config?: ConfigType;
46
+ className?: string;
47
+ }) {
48
+ const { value = { type: 'object' }, config = {}, onChange: onChangeProps } = props;
49
+ const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
50
+ value,
51
+ onChangeProps
52
+ );
53
+
54
+ return (
55
+ <UIContainer className={props.className}>
56
+ <UIProperties>
57
+ {propertyList.map((_property, index) => (
58
+ <PropertyEdit
59
+ key={_property.key}
60
+ value={_property}
61
+ config={config}
62
+ $index={index}
63
+ onChange={(_v) => {
64
+ onEditProperty(_property.key!, _v);
65
+ }}
66
+ onRemove={() => {
67
+ onRemoveProperty(_property.key!);
68
+ }}
69
+ />
70
+ ))}
71
+ </UIProperties>
72
+ <Button
73
+ size="small"
74
+ style={{ marginTop: 10, marginLeft: 16 }}
75
+ icon={<IconPlus />}
76
+ onClick={onAddProperty}
77
+ >
78
+ {config?.addButtonText ?? 'Add'}
79
+ </Button>
80
+ </UIContainer>
81
+ );
82
+ }
83
+
84
+ function PropertyEdit(props: {
85
+ value?: PropertyValueType;
86
+ config?: ConfigType;
87
+ onChange?: (value: PropertyValueType) => void;
88
+ onRemove?: () => void;
89
+ $isLast?: boolean;
90
+ $index?: number;
91
+ $isFirst?: boolean;
92
+ $parentExpand?: boolean;
93
+ $parentType?: string;
94
+ $showLine?: boolean;
95
+ $level?: number; // 添加层级属性
96
+ }) {
97
+ const {
98
+ value,
99
+ config,
100
+ $level = 0,
101
+ onChange: onChangeProps,
102
+ onRemove,
103
+ $index,
104
+ $isFirst,
105
+ $isLast,
106
+ $parentExpand = false,
107
+ $parentType = '',
108
+ $showLine,
109
+ } = props;
110
+
111
+ const [expand, setExpand] = useState(false);
112
+ const [collapse, setCollapse] = useState(false);
113
+
114
+ const { name, type, items, default: defaultValue, description, isPropertyRequired } = value || {};
115
+
116
+ const typeSelectorValue = useMemo(() => ({ type, items }), [type, items]);
117
+
118
+ const { propertyList, isDrilldownObject, onAddProperty, onRemoveProperty, onEditProperty } =
119
+ usePropertiesEdit(value, onChangeProps);
120
+
121
+ const onChange = (key: string, _value: any) => {
122
+ onChangeProps?.({
123
+ ...(value || {}),
124
+ [key]: _value,
125
+ });
126
+ };
127
+
128
+ const showCollapse = isDrilldownObject && propertyList.length > 0;
129
+
130
+ return (
131
+ <>
132
+ <UIPropertyLeft
133
+ type={type}
134
+ $index={$index}
135
+ $isFirst={$isFirst}
136
+ $isLast={$isLast}
137
+ $showLine={$showLine}
138
+ $isExpand={expand}
139
+ $parentExpand={$parentExpand}
140
+ $parentType={$parentType}
141
+ >
142
+ {showCollapse && (
143
+ <UICollapseTrigger onClick={() => setCollapse((_collapse) => !_collapse)}>
144
+ {collapse ? <IconChevronDown size="small" /> : <IconChevronRight size="small" />}
145
+ </UICollapseTrigger>
146
+ )}
147
+ </UIPropertyLeft>
148
+ <UIPropertyRight>
149
+ <UIPropertyMain
150
+ $showCollapse={showCollapse}
151
+ $collapse={collapse}
152
+ $expand={expand}
153
+ type={type}
154
+ >
155
+ <UIRow>
156
+ <UIName>
157
+ <BlurInput
158
+ placeholder={config?.placeholder ?? 'Input Variable Name'}
159
+ size="small"
160
+ value={name}
161
+ onChange={(value) => onChange('name', value)}
162
+ />
163
+ </UIName>
164
+ <UIType>
165
+ <TypeSelector
166
+ value={typeSelectorValue}
167
+ onChange={(_value) => {
168
+ onChangeProps?.({
169
+ ...(value || {}),
170
+ ..._value,
171
+ });
172
+ }}
173
+ />
174
+ </UIType>
175
+ <UIRequired>
176
+ <Checkbox
177
+ checked={isPropertyRequired}
178
+ onChange={(e) => onChange('isPropertyRequired', e.target.checked)}
179
+ />
180
+ </UIRequired>
181
+ <UIActions>
182
+ <IconButton
183
+ size="small"
184
+ theme="borderless"
185
+ icon={expand ? <IconShrink size="small" /> : <IconExpand size="small" />}
186
+ onClick={() => {
187
+ setExpand((_expand) => !_expand);
188
+ }}
189
+ />
190
+ {isDrilldownObject && (
191
+ <IconButton
192
+ size="small"
193
+ theme="borderless"
194
+ icon={<IconAddChildren />}
195
+ onClick={() => {
196
+ onAddProperty();
197
+ setCollapse(true);
198
+ }}
199
+ />
200
+ )}
201
+ <IconButton
202
+ size="small"
203
+ theme="borderless"
204
+ icon={<IconMinus size="small" />}
205
+ onClick={onRemove}
206
+ />
207
+ </UIActions>
208
+ </UIRow>
209
+ {expand && (
210
+ <UIExpandDetail>
211
+ <UILabel>{config?.descTitle ?? 'Description'}</UILabel>
212
+ <BlurInput
213
+ size="small"
214
+ value={description}
215
+ onChange={(value) => onChange('description', value)}
216
+ placeholder={config?.descPlaceholder ?? 'Help LLM to understand the property'}
217
+ />
218
+ {$level === 0 && type && type !== 'array' && (
219
+ <>
220
+ <UILabel style={{ marginTop: 10 }}>
221
+ {config?.defaultValueTitle ?? 'Default Value'}
222
+ </UILabel>
223
+ <DefaultValueWrapper>
224
+ <DefaultValue
225
+ value={defaultValue}
226
+ schema={value}
227
+ type={type}
228
+ placeholder={config?.defaultValuePlaceholder}
229
+ jsonFormatText={config?.jsonFormatText}
230
+ onChange={(value) => onChange('default', value)}
231
+ />
232
+ </DefaultValueWrapper>
233
+ </>
234
+ )}
235
+ </UIExpandDetail>
236
+ )}
237
+ </UIPropertyMain>
238
+ {showCollapse && (
239
+ <UICollapsible $collapse={collapse}>
240
+ <UIProperties $shrink={true}>
241
+ {propertyList.map((_property, index) => (
242
+ <PropertyEdit
243
+ key={_property.key}
244
+ value={_property}
245
+ config={config}
246
+ $level={$level + 1} // 传递递增的层级
247
+ $parentExpand={expand}
248
+ $parentType={type}
249
+ onChange={(_v) => {
250
+ onEditProperty(_property.key!, _v);
251
+ }}
252
+ onRemove={() => {
253
+ onRemoveProperty(_property.key!);
254
+ }}
255
+ $isLast={index === propertyList.length - 1}
256
+ $isFirst={index === 0}
257
+ $index={index}
258
+ $showLine={true}
259
+ />
260
+ ))}
261
+ </UIProperties>
262
+ </UICollapsible>
263
+ )}
264
+ </UIPropertyRight>
265
+ </>
266
+ );
267
+ }
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React from 'react';
7
+
8
+ import styled, { css } from 'styled-components';
9
+ import Icon from '@douyinfe/semi-icons';
10
+
11
+ export const UIContainer = styled.div`
12
+ /* & .semi-input {
13
+ background-color: #fff;
14
+ border-radius: 6px;
15
+ height: 24px;
16
+ } */
17
+ `;
18
+
19
+ export const UIRow = styled.div`
20
+ display: flex;
21
+ align-items: center;
22
+ gap: 6px;
23
+ `;
24
+
25
+ export const UICollapseTrigger = styled.div`
26
+ cursor: pointer;
27
+ margin-right: 5px;
28
+ `;
29
+
30
+ export const UIExpandDetail = styled.div`
31
+ display: flex;
32
+ flex-direction: column;
33
+ `;
34
+
35
+ export const UILabel = styled.div`
36
+ font-size: 12px;
37
+ color: #999;
38
+ font-weight: 400;
39
+ margin-bottom: 2px;
40
+ `;
41
+
42
+ export const UIProperties = styled.div<{ $shrink?: boolean }>`
43
+ display: grid;
44
+ grid-template-columns: auto 1fr;
45
+
46
+ ${({ $shrink }) =>
47
+ $shrink &&
48
+ css`
49
+ padding-left: 10px;
50
+ margin-top: 10px;
51
+ `}
52
+ `;
53
+
54
+ export const UIPropertyLeft = styled.div<{
55
+ $isLast?: boolean;
56
+ $showLine?: boolean;
57
+ $isExpand?: boolean;
58
+ type?: string;
59
+ $isFirst?: boolean;
60
+ $index?: number;
61
+ $parentExpand?: boolean;
62
+ $parentType?: string;
63
+ }>`
64
+ grid-column: 1;
65
+ position: relative;
66
+ width: 16px;
67
+
68
+ ${({ $showLine, $isLast, $parentType }) => {
69
+ let height = '100%';
70
+ if ($parentType && $isLast) {
71
+ height = '24px';
72
+ }
73
+
74
+ return (
75
+ $showLine &&
76
+ css`
77
+ &::before {
78
+ /* 竖线 */
79
+ content: '';
80
+ height: ${height};
81
+ position: absolute;
82
+ left: -22px;
83
+ top: -16px;
84
+ width: 1px;
85
+ background: #d9d9d9;
86
+ display: block;
87
+ }
88
+
89
+ &::after {
90
+ /* 横线 */
91
+ content: '';
92
+ position: absolute;
93
+ left: -22px; // 横线起点和竖线对齐
94
+ top: 8px; // 跟随你的行高调整
95
+ width: 18px; // 横线长度
96
+ height: 1px;
97
+ background: #d9d9d9;
98
+ display: block;
99
+ }
100
+ `
101
+ );
102
+ }}
103
+ `;
104
+
105
+ export const UIPropertyRight = styled.div`
106
+ grid-column: 2;
107
+ margin-bottom: 10px;
108
+
109
+ &:last-child {
110
+ margin-bottom: 0px;
111
+ }
112
+ `;
113
+
114
+ export const UIPropertyMain = styled.div<{
115
+ $expand?: boolean;
116
+ type?: string;
117
+ $collapse?: boolean;
118
+ $showCollapse?: boolean;
119
+ }>`
120
+ display: flex;
121
+ flex-direction: column;
122
+ gap: 10px;
123
+ position: relative;
124
+
125
+ ${({ $expand, type, $collapse, $showCollapse }) => {
126
+ const beforeElement = `
127
+ &::before {
128
+ /* 竖线 */
129
+ content: '';
130
+ height: 100%;
131
+ position: absolute;
132
+ left: -12px;
133
+ top: 18px;
134
+ width: 1px;
135
+ background: #d9d9d9;
136
+ display: block;
137
+ }`;
138
+
139
+ return (
140
+ $expand &&
141
+ css`
142
+ background-color: #f5f5f5;
143
+ padding: 10px;
144
+ border-radius: 4px;
145
+
146
+ ${$showCollapse &&
147
+ $collapse &&
148
+ (type === 'array' || type === 'object') &&
149
+ css`
150
+ ${beforeElement}
151
+ `}
152
+ `
153
+ );
154
+ }}
155
+ `;
156
+
157
+ export const UICollapsible = styled.div<{ $collapse?: boolean }>`
158
+ display: none;
159
+
160
+ ${({ $collapse }) =>
161
+ $collapse &&
162
+ css`
163
+ display: block;
164
+ `}
165
+ `;
166
+
167
+ export const UIName = styled.div`
168
+ flex-grow: 1;
169
+ `;
170
+
171
+ export const UIType = styled.div``;
172
+
173
+ export const UIRequired = styled.div``;
174
+
175
+ export const UIActions = styled.div`
176
+ white-space: nowrap;
177
+ `;
178
+
179
+ const iconAddChildrenSvg = (
180
+ <svg
181
+ className="icon-icon icon-icon-coz_add_node "
182
+ width="1em"
183
+ height="1em"
184
+ viewBox="0 0 24 24"
185
+ fill="currentColor"
186
+ xmlns="http://www.w3.org/2000/svg"
187
+ >
188
+ <path
189
+ fillRule="evenodd"
190
+ clipRule="evenodd"
191
+ d="M11 6.49988C11 8.64148 9.50397 10.4337 7.49995 10.8884V15.4998C7.49995 16.0521 7.94767 16.4998 8.49995 16.4998H11.208C11.0742 16.8061 11 17.1443 11 17.4998C11 17.8554 11.0742 18.1936 11.208 18.4998H8.49995C6.8431 18.4998 5.49995 17.1567 5.49995 15.4998V10.8884C3.49599 10.4336 2 8.64145 2 6.49988C2 4.0146 4.01472 1.99988 6.5 1.99988C8.98528 1.99988 11 4.0146 11 6.49988ZM6.5 8.99988C7.88071 8.99988 9 7.88059 9 6.49988C9 5.11917 7.88071 3.99988 6.5 3.99988C5.11929 3.99988 4 5.11917 4 6.49988C4 7.88059 5.11929 8.99988 6.5 8.99988Z"
192
+ ></path>
193
+ <path d="M17.5 12.4999C18.0523 12.4999 18.5 12.9476 18.5 13.4999V16.4999H21.5C22.0523 16.4999 22.5 16.9476 22.5 17.4999C22.5 18.0522 22.0523 18.4999 21.5 18.4999H18.5V21.4999C18.5 22.0522 18.0523 22.4999 17.5 22.4999C16.9477 22.4999 16.5 22.0522 16.5 21.4999V18.4999H13.5C12.9477 18.4999 12.5 18.0522 12.5 17.4999C12.5 16.9476 12.9477 16.4999 13.5 16.4999H16.5V13.4999C16.5 12.9476 16.9477 12.4999 17.5 12.4999Z"></path>
194
+ </svg>
195
+ );
196
+
197
+ export const IconAddChildren = () => <Icon size="small" svg={iconAddChildrenSvg} />;
198
+
199
+ export const DefaultValueWrapper = styled.div`
200
+ margin: 0;
201
+ `;
202
+
203
+ export const JSONViewerWrapper = styled.div`
204
+ padding: 0 0 24px;
205
+ &:first-child {
206
+ margin-top: 0px;
207
+ }
208
+ `;
209
+
210
+ export const JSONHeader = styled.div`
211
+ display: flex;
212
+ justify-content: space-between;
213
+ align-items: center;
214
+ background-color: var(--semi-color-fill-0);
215
+ border-radius: 6px 6px 0 0;
216
+ height: 36px;
217
+ padding: 0 8px 0 12px;
218
+ `;
219
+
220
+ export const JSONHeaderLeft = styled.div`
221
+ display: flex;
222
+ align-items: center;
223
+ gap: 10px;
224
+ `;
225
+
226
+ export const JSONHeaderRight = styled.div`
227
+ display: flex;
228
+ align-items: center;
229
+ gap: 10px;
230
+ `;
231
+
232
+ export const ConstantInputWrapper = styled.div`
233
+ flex-grow: 1;
234
+
235
+ & .semi-tree-select,
236
+ & .semi-input-number,
237
+ & .semi-select {
238
+ width: 100%;
239
+ }
240
+ `;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { IJsonSchema } from '../../typings';
7
+
8
+ export interface PropertyValueType extends IJsonSchema {
9
+ name?: string;
10
+ key?: number;
11
+ isPropertyRequired?: boolean;
12
+ }
13
+
14
+ export type PropertiesValueType = Pick<PropertyValueType, 'properties' | 'required'>;
15
+
16
+ export type JsonSchemaProperties = IJsonSchema['properties'];
17
+
18
+ export interface ConfigType {
19
+ placeholder?: string;
20
+ descTitle?: string;
21
+ descPlaceholder?: string;
22
+ defaultValueTitle?: string;
23
+ defaultValuePlaceholder?: string;
24
+ addButtonText?: string;
25
+ jsonFormatText?: string;
26
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Return the corresponding string description according to the type of the input value.根据输入值的类型返回对应的字符串描述。
8
+ * @param value - 需要判断类型的值。The value whose type needs to be judged.
9
+ * @returns 返回值的类型字符串 The type string of the return value('string', 'integer', 'number', 'boolean', 'object', 'array', 'other')。
10
+ */
11
+ export function getValueType(value: any): string {
12
+ const type = typeof value;
13
+
14
+ if (type === 'string') {
15
+ return 'string';
16
+ } else if (type === 'number') {
17
+ return Number.isInteger(value) ? 'integer' : 'number';
18
+ } else if (type === 'boolean') {
19
+ return 'boolean';
20
+ } else if (type === 'object') {
21
+ if (value === null) {
22
+ return 'other';
23
+ }
24
+ return Array.isArray(value) ? 'array' : 'object';
25
+ } else {
26
+ // undefined, function, symbol, bigint etc.
27
+ return 'other';
28
+ }
29
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "prompt-editor",
3
+ "depMaterials": [],
4
+ "depPackages": [
5
+ "@coze-editor/editor@0.1.0-alpha.879fbb",
6
+ "@codemirror/view",
7
+ "styled-components"
8
+ ]
9
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { useLayoutEffect } from 'react';
7
+
8
+ import { useInjector } from '@coze-editor/editor/react';
9
+ import { astDecorator } from '@coze-editor/editor';
10
+ import { EditorView } from '@codemirror/view';
11
+
12
+ function JinjaHighlight() {
13
+ const injector = useInjector();
14
+
15
+ useLayoutEffect(
16
+ () =>
17
+ injector.inject([
18
+ astDecorator.whole.of((cursor) => {
19
+ if (cursor.name === 'JinjaStatementStart' || cursor.name === 'JinjaStatementEnd') {
20
+ return {
21
+ type: 'className',
22
+ className: 'jinja-statement-bracket',
23
+ };
24
+ }
25
+
26
+ if (cursor.name === 'JinjaComment') {
27
+ return {
28
+ type: 'className',
29
+ className: 'jinja-comment',
30
+ };
31
+ }
32
+
33
+ if (cursor.name === 'JinjaExpression') {
34
+ return {
35
+ type: 'className',
36
+ className: 'jinja-expression',
37
+ };
38
+ }
39
+ }),
40
+ EditorView.theme({
41
+ '.jinja-statement-bracket': {
42
+ color: '#D1009D',
43
+ },
44
+ '.jinja-comment': {
45
+ color: '#0607094D',
46
+ },
47
+ '.jinja-expression': {
48
+ color: '#4E40E5',
49
+ },
50
+ }),
51
+ ]),
52
+ [injector]
53
+ );
54
+
55
+ return null;
56
+ }
57
+
58
+ export default JinjaHighlight;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { useLayoutEffect } from 'react';
7
+
8
+ import { useInjector } from '@coze-editor/editor/react';
9
+ import { languageSupport } from '@coze-editor/editor/preset-prompt';
10
+
11
+ function LanguageSupport() {
12
+ const injector = useInjector();
13
+
14
+ useLayoutEffect(() => injector.inject([languageSupport]), [injector]);
15
+
16
+ return null;
17
+ }
18
+
19
+ export default LanguageSupport;