-
Notifications
You must be signed in to change notification settings - Fork 2
[SRLT-118] 리팩토링 #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
The head ref may contain hidden characters: "SRLT-118-\uB9AC\uD329\uD1A0\uB9C1"
Merged
[SRLT-118] 리팩토링 #87
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
535d89f
feat: (SRLT-118) 단일 항목 저장 함수 추가 및 교체
parknari02 6222f53
refactor: (SRLT-118) writeform 전체 리팩토링
parknari02 6b49ed2
Merge branch 'main' of https://github.com/StartUpLight/STARLIGHT_FE i…
parknari02 e672900
refactor: (SRLT-118) 함수 위치 재정의
parknari02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| import StarterKit from '@tiptap/starter-kit'; | ||
| import Highlight from '@tiptap/extension-highlight'; | ||
| import TextStyle from '@tiptap/extension-text-style'; | ||
| import Color from '@tiptap/extension-color'; | ||
| import Placeholder from '@tiptap/extension-placeholder'; | ||
| import Table from '@tiptap/extension-table'; | ||
| import TableRow from '@tiptap/extension-table-row'; | ||
| import TableHeader from '@tiptap/extension-table-header'; | ||
| import TableCell from '@tiptap/extension-table-cell'; | ||
| import type { Editor } from '@tiptap/core'; | ||
| import type { EditorView } from '@tiptap/pm/view'; | ||
| import SpellError from '@/util/spellError'; | ||
| import { | ||
| DeleteTableOnDelete, | ||
| ResizableImage, | ||
| SelectTableOnBorderClick, | ||
| EnsureTrailingParagraph, | ||
| } from './extensions'; | ||
| import { uploadImage } from '@/lib/imageUpload'; | ||
| import { getImageDimensions, clampImageDimensions } from '@/lib/getImageDimensions'; | ||
| import { ImageCommandAttributes } from '@/types/business/business.type'; | ||
| import { getSelectionAvailableWidth } from './getSelectionAvailableWidth'; | ||
|
|
||
| // 공통 에디터 확장 (표, 이미지, 하이라이트 등 모든 기능 포함) | ||
| export const COMMON_EXTENSIONS = [ | ||
| StarterKit, | ||
| SpellError, | ||
| DeleteTableOnDelete, | ||
| Highlight.configure({ multicolor: true }), | ||
| TextStyle, | ||
| Color, | ||
| ResizableImage.configure({ inline: false }), | ||
| Table.configure({ resizable: true }), | ||
| TableRow, | ||
| TableHeader, | ||
| TableCell, | ||
| SelectTableOnBorderClick, | ||
| EnsureTrailingParagraph, | ||
| ]; | ||
|
|
||
| // 간단한 에디터 확장 (하이라이트, 볼드, 색상만 가능, 헤딩/표/이미지 비활성화) | ||
| export const SIMPLE_EXTENSIONS = [ | ||
| StarterKit.configure({ | ||
| heading: false, | ||
| blockquote: false, | ||
| codeBlock: false, | ||
| horizontalRule: false, | ||
| hardBreak: false, | ||
| }), | ||
| SpellError, | ||
| Highlight.configure({ multicolor: true }), | ||
| TextStyle, | ||
| Color, | ||
| ]; | ||
|
|
||
| // 이미지 붙여넣기 핸들러 생성 | ||
| const createPasteHandler = () => { | ||
| return (view: EditorView, event: ClipboardEvent) => { | ||
| const items = Array.from(event.clipboardData?.items || []); | ||
| const imageItem = items.find( | ||
| (item) => item.type.indexOf('image') !== -1 | ||
| ); | ||
|
|
||
| if (imageItem) { | ||
| event.preventDefault(); | ||
| const file = imageItem.getAsFile(); | ||
| if (file) { | ||
| // 파일 크기 제한 (5MB) | ||
| // const maxSize = 5 * 1024 * 1024; | ||
| // if (file.size > maxSize) { | ||
| // alert('이미지 크기는 5MB 이하여야 합니다.'); | ||
| // return true; | ||
| // } | ||
|
|
||
| // 비동기로 업로드 처리 | ||
| uploadImage(file) | ||
| .then(async (imageUrl) => { | ||
| if (imageUrl) { | ||
| const editor = (view as EditorView & { editor?: Editor }).editor; | ||
| const { width, height } = await getImageDimensions(imageUrl); | ||
| const selectionWidth = getSelectionAvailableWidth(editor ?? null); | ||
| const fallbackWidth = view.dom?.clientWidth ? view.dom.clientWidth - 48 : undefined; | ||
| const maxWidth = selectionWidth ?? fallbackWidth; | ||
| const { width: clampedWidth, height: clampedHeight } = clampImageDimensions(width, height, maxWidth ?? undefined); | ||
| const imageAttributes: ImageCommandAttributes = { | ||
| src: imageUrl, | ||
| width: clampedWidth ?? undefined, | ||
| height: clampedHeight ?? undefined, | ||
| }; | ||
| editor | ||
| ?.chain() | ||
| .focus() | ||
| .setImage(imageAttributes) | ||
| .run(); | ||
| } | ||
| }) | ||
| .catch((error) => { | ||
| console.error('이미지 업로드 실패:', error); | ||
| alert('이미지 업로드에 실패했습니다. 다시 시도해주세요.'); | ||
| }); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; | ||
| }; | ||
|
|
||
| // 에디터 설정 생성 함수들 | ||
| export const createEditorFeaturesConfig = () => ({ | ||
| extensions: [ | ||
| ...COMMON_EXTENSIONS, | ||
| Placeholder.configure({ | ||
| placeholder: '아이템의 핵심기능은 무엇이며, 어떤 기능을 구현·작동 하는지 설명해주세요.', | ||
| includeChildren: false, | ||
| showOnlyWhenEditable: true, | ||
| }), | ||
| ], | ||
| content: '<p></p>', | ||
| editorProps: { handlePaste: createPasteHandler() }, | ||
| immediatelyRender: false, | ||
| }); | ||
|
|
||
| export const createEditorSkillsConfig = () => ({ | ||
| extensions: [ | ||
| ...COMMON_EXTENSIONS, | ||
| Placeholder.configure({ | ||
| placeholder: '보유한 기술 및 지식재산권이 별도로 없을 경우, 아이템에 필요한 핵심기술을 어떻게 개발해 나갈것인지 계획에 대해 작성해주세요. \n ※ 지식재산권: 특허, 상표권, 디자인, 실용신안권 등.', | ||
| includeChildren: false, | ||
| showOnlyWhenEditable: true, | ||
| }), | ||
| ], | ||
| content: '<p></p>', | ||
| editorProps: { handlePaste: createPasteHandler() }, | ||
| immediatelyRender: false, | ||
| }); | ||
|
|
||
| export const createEditorGoalsConfig = () => ({ | ||
| extensions: [ | ||
| ...COMMON_EXTENSIONS, | ||
| Placeholder.configure({ | ||
| placeholder: '본 사업을 통해 달성하고 싶은 궁극적인 목표에 대해 설명', | ||
| includeChildren: false, | ||
| showOnlyWhenEditable: true, | ||
| }), | ||
| ], | ||
| content: '<p></p>', | ||
| editorProps: { handlePaste: createPasteHandler() }, | ||
| immediatelyRender: false, | ||
| }); | ||
|
|
||
| export const createEditorItemNameConfig = () => ({ | ||
| extensions: [ | ||
| ...SIMPLE_EXTENSIONS, | ||
| Placeholder.configure({ | ||
| placeholder: '답변을 입력하세요.', | ||
| includeChildren: false, | ||
| showOnlyWhenEditable: true, | ||
| }), | ||
| ], | ||
| content: '<p></p>', | ||
| immediatelyRender: false, | ||
| }); | ||
|
|
||
| export const createEditorOneLineIntroConfig = () => ({ | ||
| extensions: [ | ||
| ...SIMPLE_EXTENSIONS, | ||
| Placeholder.configure({ | ||
| placeholder: '답변을 입력하세요.', | ||
| includeChildren: false, | ||
| showOnlyWhenEditable: true, | ||
| }), | ||
| ], | ||
| content: '<p></p>', | ||
| immediatelyRender: false, | ||
| }); | ||
|
|
||
| export const createEditorGeneralConfig = () => ({ | ||
| extensions: [ | ||
| ...COMMON_EXTENSIONS, | ||
| Placeholder.configure({ | ||
| placeholder: '세부 항목별 체크리스트를 참고하며 작성해주시면, 리포트 점수가 올라갑니다.', | ||
| includeChildren: false, | ||
| showOnlyWhenEditable: true, | ||
| }), | ||
| ], | ||
| content: '<p></p>', | ||
| editorProps: { handlePaste: createPasteHandler() }, | ||
| immediatelyRender: false, | ||
| }); | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the actual file and surrounding context wc -l src/lib/business/editor/editorConstants.tsRepository: StartUpLight/STARLIGHT_FE
Length of output: 115
🏁 Script executed:
Repository: StartUpLight/STARLIGHT_FE
Length of output: 1736
🏁 Script executed:
Repository: StartUpLight/STARLIGHT_FE
Length of output: 8153
🌐 Web query:
TipTap EditorView handlePaste access editor instance recommended approach💡 Result:
Short answer — don’t try to reach into Tiptap’s Editor from a raw ProseMirror handlePaste; use Tiptap’s APIs instead (paste rules, extension plugins or editor events). Recommended options:
For content transforms (text/HTML → nodes/marks): implement addPasteRules() in a Node/Mark/Extension. It’s the high‑level Tiptap way to intercept and transform pasted content. [1]
For more complex/custom paste logic (need access to view/state/dispatch): add a ProseMirror plugin from an extension via addProseMirrorPlugins() and implement handlePaste(view, event, slice) there. You receive the ProseMirror EditorView and Slice (ProseMirror API) to dispatch transactions. Use this only when pasteRules aren’t enough. (ProseMirror handlePaste signature). [2][3]
For file/image pastes: use the official @tiptap/extension-file-handler (onPaste / onDrop) which supplies the Tiptap editor instance and pasted files — convenient and recommended for uploads. [4]
Alternatively, for global behavior: register an editor-level "paste" event when creating the Editor (editor.on('paste', ...)) or use the EditorContext/hooks in React integrations to access the editor instance. [1][5]
References
If you want, tell me which exact paste behavior you need and I’ll show the minimal addPasteRules or addProseMirrorPlugins example.
🏁 Script executed:
Repository: StartUpLight/STARLIGHT_FE
Length of output: 51
🏁 Script executed:
Repository: StartUpLight/STARLIGHT_FE
Length of output: 1081
ProseMirror 플러그인을 통해 에디터 인스턴스에 안전하게 접근하세요.
(view as EditorView & { editor?: Editor }).editor는 TipTap의 공식 API가 아닌 내부 구현에 의존합니다. TipTap 버전 업그레이드 시 동작이 변경될 수 있습니다.권장 방안:
현재 패턴을 위의 공식 방식으로 리팩토링하는 것을 권장합니다.
🤖 Prompt for AI Agents