Skip to content

Commit

Permalink
feat(template-editor): 为模板编辑器添加默认值属性
Browse files Browse the repository at this point in the history
- 在 DingTemplateEditor、FeishuTemplateEditor 和 WechatTemplateEditor 组件中添加 defaultValue 属性
- 将 defaultValue 传递给底层的 CodeMirror 组件
- 此功能允许用户在没有值时显示默认模板
  • Loading branch information
aide-cloud committed Jan 15, 2025
1 parent 2730b38 commit 2342903
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/components/data/child/template-editor-ding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import suggestions from './config/suggestions'

export interface DingTemplateEditorProps {
value?: string
defaultValue?: string
onChange?: (value: string) => void
height?: string | number
}
Expand All @@ -16,7 +17,12 @@ const { useToken } = antTheme

const language = 'json'

export const DingTemplateEditor: React.FC<DingTemplateEditorProps> = ({ value, onChange, height = '40vh' }) => {
export const DingTemplateEditor: React.FC<DingTemplateEditorProps> = ({
value,
defaultValue,
onChange,
height = '40vh'
}) => {
const { theme } = useContext(GlobalContext)
const { token } = useToken()
const editorRef = useRef(null)
Expand Down Expand Up @@ -146,6 +152,7 @@ export const DingTemplateEditor: React.FC<DingTemplateEditorProps> = ({ value, o
height={height}
defaultLanguage={language}
value={value}
defaultValue={defaultValue}
onChange={(value) => onChange?.(value || '')}
onMount={handleEditorDidMount}
options={{
Expand Down
9 changes: 8 additions & 1 deletion src/components/data/child/template-editor-feishu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import suggestions from './config/suggestions'

export interface FeishuTemplateEditorProps {
value?: string
defaultValue?: string
onChange?: (value: string) => void
height?: string | number
}
Expand All @@ -16,7 +17,12 @@ const { useToken } = antTheme

const language = 'json'

export const FeishuTemplateEditor: React.FC<FeishuTemplateEditorProps> = ({ value, onChange, height = '40vh' }) => {
export const FeishuTemplateEditor: React.FC<FeishuTemplateEditorProps> = ({
value,
defaultValue,
onChange,
height = '40vh'
}) => {
const { theme } = useContext(GlobalContext)
const { token } = useToken()
const editorRef = useRef(null)
Expand Down Expand Up @@ -146,6 +152,7 @@ export const FeishuTemplateEditor: React.FC<FeishuTemplateEditorProps> = ({ valu
height={height}
defaultLanguage={language}
value={value}
defaultValue={defaultValue}
onChange={(value) => onChange?.(value || '')}
onMount={handleEditorDidMount}
options={{
Expand Down
9 changes: 8 additions & 1 deletion src/components/data/child/template-editor-wechat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { wechatJsonSchema } from './config/wechat'

export interface WechatTemplateEditorProps {
value?: string
defaultValue?: string
onChange?: (value: string) => void
height?: string | number
}
Expand All @@ -16,7 +17,12 @@ const { useToken } = antTheme

const language = 'json'

export const WechatTemplateEditor: React.FC<WechatTemplateEditorProps> = ({ value, onChange, height = '40vh' }) => {
export const WechatTemplateEditor: React.FC<WechatTemplateEditorProps> = ({
value,
defaultValue,
onChange,
height = '40vh'
}) => {
const { theme } = useContext(GlobalContext)
const { token } = useToken()
const editorRef = useRef(null)
Expand Down Expand Up @@ -146,6 +152,7 @@ export const WechatTemplateEditor: React.FC<WechatTemplateEditorProps> = ({ valu
height={height}
defaultLanguage={language}
value={value}
defaultValue={defaultValue}
onChange={(value) => onChange?.(value || '')}
onMount={handleEditorDidMount}
options={{
Expand Down

0 comments on commit 2342903

Please sign in to comment.