diff --git a/lerna.json b/lerna.json index d062e98bfc..40903ea75e 100644 --- a/lerna.json +++ b/lerna.json @@ -2,9 +2,7 @@ "version": "1.2.1-alpha", "npmClient": "yarn", "useWorkspaces": true, - "npmClientArgs": [ - "--ignore-engines" - ], + "npmClientArgs": ["--ignore-engines"], "command": { "version": { "forcePublish": true, diff --git a/packages/core/client/src/schema-component/antd/markdown/Markdown.Void.tsx b/packages/core/client/src/schema-component/antd/markdown/Markdown.Void.tsx index b8fa8a6a65..b7fca15a1d 100644 --- a/packages/core/client/src/schema-component/antd/markdown/Markdown.Void.tsx +++ b/packages/core/client/src/schema-component/antd/markdown/Markdown.Void.tsx @@ -9,36 +9,83 @@ import { observer, useField, useFieldSchema } from '@formily/react'; import { Input as AntdInput, Button, Space, Spin, theme } from 'antd'; +import type { TextAreaRef } from 'antd/es/input/TextArea'; import cls from 'classnames'; -import React, { useState } from 'react'; +import React, { useCallback, useEffect, useState, useRef, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { useGlobalTheme } from '../../../global-theme'; import { useDesignable } from '../../hooks/useDesignable'; import { MarkdownVoidDesigner } from './Markdown.Void.Designer'; import { useStyles } from './style'; -import { useParseMarkdown } from './util'; +import { parseMarkdown } from './util'; import { TextAreaProps } from 'antd/es/input'; import { useBlockHeight } from '../../hooks/useBlockSize'; - +import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps'; +import { useCollectionRecord } from '../../../data-source'; +import { useVariableOptions } from '../../../schema-settings/VariableInput/hooks/useVariableOptions'; +import { VariableSelect } from '../variable/VariableSelect'; +import { replaceVariableValue } from '../../../block-provider/hooks'; +import { useLocalVariables, useVariables } from '../../../variables'; +import { registerQrcodeWebComponent } from './qrcode-webcom'; export interface MarkdownEditorProps extends Omit { + scope: any[]; defaultValue?: string; onSubmit?: (value: string) => void; onCancel?: (e: React.MouseEvent) => void; } const MarkdownEditor = (props: MarkdownEditorProps) => { + const { scope } = props; const { t } = useTranslation(); const [value, setValue] = useState(props.defaultValue); + const inputRef = useRef(null); + const [options, setOptions] = useState([]); + const [curPos, setCurPos] = useState(null); + useEffect(() => { + setOptions(scope); + }, [scope]); + + useEffect(() => { + const inputEle = inputRef?.current?.resizableTextArea?.textArea; + if (curPos && inputEle) { + inputEle.setSelectionRange(curPos, curPos); + } + }, [curPos]); + + const onInsert = useCallback( + function (paths: string[]) { + const variable: string[] = paths.filter((key) => Boolean(key.trim())); + const { current } = inputRef; + const inputEle = current?.resizableTextArea?.textArea; + if (!inputEle || !variable) { + return; + } + current.focus(); + const templateVar = `{{${paths.join('.')}}}`; + const startPos = inputEle.selectionStart || 0; + const newVal = value.substring(0, startPos) + templateVar + value.substring(startPos, value.length); + const newPos = startPos + templateVar.length; + setValue(newVal); + setCurPos(newPos); + }, + [value], + ); return ( -
+
{ setValue(e.target.value); }} + style={{ paddingBottom: '40px' }} /> +
+ +
+