diff --git a/web/app/components/base/prompt-editor/index.tsx b/web/app/components/base/prompt-editor/index.tsx index 99e3a3325c..560a9e8c10 100644 --- a/web/app/components/base/prompt-editor/index.tsx +++ b/web/app/components/base/prompt-editor/index.tsx @@ -34,6 +34,7 @@ import { UPDATE_DATASETS_EVENT_EMITTER, UPDATE_HISTORY_EVENT_EMITTER, } from './constants' +import styles from './line-numbers.module.css' import ComponentPickerBlock from './plugins/component-picker-block' import { ContextBlock, @@ -46,12 +47,12 @@ import { CurrentBlockReplacementBlock, } from './plugins/current-block' import { CustomTextNode } from './plugins/custom-text/node' + import { ErrorMessageBlock, ErrorMessageBlockNode, ErrorMessageBlockReplacementBlock, } from './plugins/error-message-block' - import { HistoryBlock, HistoryBlockNode, @@ -88,6 +89,7 @@ export type PromptEditorProps = { className?: string placeholder?: string | React.ReactNode placeholderClassName?: string + showLineNumbers?: boolean style?: React.CSSProperties value?: string editable?: boolean @@ -113,6 +115,7 @@ const PromptEditor: FC = ({ className, placeholder, placeholderClassName, + showLineNumbers, style, value, editable = true, @@ -178,13 +181,14 @@ const PromptEditor: FC = ({ return ( -
+
= ({ placeholder={( )} diff --git a/web/app/components/base/prompt-editor/line-numbers.module.css b/web/app/components/base/prompt-editor/line-numbers.module.css new file mode 100644 index 0000000000..5238233700 --- /dev/null +++ b/web/app/components/base/prompt-editor/line-numbers.module.css @@ -0,0 +1,52 @@ +.lineNumbersScope { + --line-number-gutter: 32px; + --line-number-gap: 12px; +} + +.lineNumbers { + counter-reset: line; + padding-left: calc(var(--line-number-gutter) + var(--line-number-gap)); +} + +.lineNumbers :global(p), +.lineNumbers :global(h1), +.lineNumbers :global(h2), +.lineNumbers :global(h3), +.lineNumbers :global(h4), +.lineNumbers :global(h5), +.lineNumbers :global(h6), +.lineNumbers :global(li), +.lineNumbers :global(blockquote), +.lineNumbers :global(pre) { + position: relative; + display: block; + min-height: 1.5em; +} + +.lineNumbers :global(p)::before, +.lineNumbers :global(h1)::before, +.lineNumbers :global(h2)::before, +.lineNumbers :global(h3)::before, +.lineNumbers :global(h4)::before, +.lineNumbers :global(h5)::before, +.lineNumbers :global(h6)::before, +.lineNumbers :global(li)::before, +.lineNumbers :global(blockquote)::before, +.lineNumbers :global(pre)::before { + counter-increment: line; + content: counter(line); + position: absolute; + top: 0; + left: calc(-1 * (var(--line-number-gutter) + var(--line-number-gap))); + width: var(--line-number-gutter); + text-align: right; + color: var(--color-text-quaternary); + line-height: inherit; + user-select: none; + pointer-events: none; +} + +.lineNumbersPlaceholder { + pointer-events: none; + left: calc(var(--line-number-gutter) + var(--line-number-gap)); +} diff --git a/web/app/components/workflow/skill/editor/markdown-file-editor.tsx b/web/app/components/workflow/skill/editor/markdown-file-editor.tsx index 7744c21584..b80dd4f693 100644 --- a/web/app/components/workflow/skill/editor/markdown-file-editor.tsx +++ b/web/app/components/workflow/skill/editor/markdown-file-editor.tsx @@ -1,23 +1,21 @@ import type { FC } from 'react' import * as React from 'react' -import PromptEditor from '@/app/components/workflow/nodes/_base/components/prompt/editor' +import PromptEditor from '@/app/components/base/prompt-editor' type MarkdownFileEditorProps = { - title: string value: string onChange: (value: string) => void } -const MarkdownFileEditor: FC = ({ title, value, onChange }) => { +const MarkdownFileEditor: FC = ({ value, onChange }) => { return ( -
+
) diff --git a/web/app/components/workflow/skill/skill-doc-editor.tsx b/web/app/components/workflow/skill/skill-doc-editor.tsx index fa645dc096..58e41f10ca 100644 --- a/web/app/components/workflow/skill/skill-doc-editor.tsx +++ b/web/app/components/workflow/skill/skill-doc-editor.tsx @@ -211,7 +211,6 @@ const SkillDocEditor: FC = () => {
{isMarkdown && (