Skip to content

[Feat] #106 - Novel 스타일 슬래시 커맨드 RichEditor 구현#107

Merged
kimsman06 merged 12 commits into
devfrom
feat/rich-editor
May 7, 2026
Merged

[Feat] #106 - Novel 스타일 슬래시 커맨드 RichEditor 구현#107
kimsman06 merged 12 commits into
devfrom
feat/rich-editor

Conversation

@kimsman06
Copy link
Copy Markdown
Collaborator

@kimsman06 kimsman06 commented May 4, 2026

🔎 What is this PR?


📝 Changes

  • src/shared/ui/rich-editor/rich-editor.tsx 슬래시 커맨드 UX로 전면 재작성 (기존 툴바 제거)
  • slash-command.ts: @tiptap/suggestion 기반 Tiptap Extension + 검색 헬퍼 신규 작성
  • slash-command-menu.tsx: 커서 기준으로 Portal 렌더되는 슬래시 메뉴 UI 신규 작성
  • 슬래시 커맨드 8종 구현 (제목 1~3, 불릿/숫자 리스트, 인용구, 코드 블록, 이미지)
  • Tiptap 확장 통합: Image, Link, Placeholder, TextStyle, Color, GlobalDragHandle, AutoJoiner
  • 슬래시 메뉴용 아이콘 7종 추가 (Heading1/2/3, ListBullet, ListOrdered, Quote, Code) — 기존 @/shared/ui/icons 컨벤션 준수
  • Storybook: Default / WithContent / ReadOnly / Portfolio·Notice Placeholder 변형

📚 Background / Context


✔ Checklist

  • 코드는 로컬에서 정상적으로 빌드됩니다 (pnpm build)
  • ESLint / Prettier 통과 (pnpm lint)
  • 네이밍/레이어 컨벤션 준수 (camelCase/PascalCase, is·has 불린 접두사, alias 계층 규칙)
  • 관련 문서/주석 반영 (필요 시)
  • 주요 로직에 테스트 또는 검증 완료

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a rich text editor component with support for headings, lists, quotes, code blocks, images, and links.
    • Introduced slash command menu for quick access to formatting options while editing.
    • Added new formatting icons (headings, lists, quotes, and code) to the UI library.
  • Documentation

    • Added Storybook stories for the rich text editor demonstrating various configurations and use cases.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@kimsman06 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 12 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b99da5ca-287f-48b1-bb5a-713197c1ced1

📥 Commits

Reviewing files that changed from the base of the PR and between 9e80dfc and 73f4499.

📒 Files selected for processing (3)
  • src/shared/ui/icons/index.tsx
  • src/shared/ui/rich-editor/rich-editor.tsx
  • src/shared/ui/rich-editor/slash-command-menu.tsx
📝 Walkthrough

Walkthrough

This PR introduces a Tiptap-based RichEditor component with slash-command functionality and supporting UI components. It adds seven new formatting icons (headings, lists, quote, code), implements the rich editor with keyboard-driven command menu, creates a slash-command Tiptap extension, and refactors existing modal story state patterns for consistency.

Changes

Modal Story Refactoring

Layer / File(s) Summary
State Synchronization
src/shared/ui/modal/modal.stories.tsx
FilterModalExample and ProfileEditModalExample consolidate controlled/uncontrolled logic into simpler internal state with useEffect syncing from propsIsOpen and explicit handleClose callbacks.
Story Configuration
src/shared/ui/modal/modal.stories.tsx
Story args now explicitly include isOpen: false, onClose: () => {}, and children: null defaults.

Rich Editor with Slash Commands

Layer / File(s) Summary
Icon Components
src/shared/ui/icons/index.tsx
Seven new React.FC<IconProps> SVG icons added: Heading1Icon, Heading2Icon, Heading3Icon, ListBulletIcon, ListOrderedIcon, QuoteIcon, CodeIcon for slash-command menu rendering.
Slash Command Extension
src/shared/ui/rich-editor/slash-command.ts
Defines SlashCommandItem shape, implements Tiptap SlashCommand extension triggered by / with suggestion wiring, and provides filterSuggestionItems helper for query-based filtering.
Slash Command Menu UI
src/shared/ui/rich-editor/slash-command-menu.tsx
SlashCommandMenu component renders command items in a DOM portal with keyboard-driven selectedIndex, auto-scrolling, and item selection via onSelect callback.
Core Editor Component
src/shared/ui/rich-editor/rich-editor.tsx
RichEditor integrates Tiptap with extensions (StarterKit, Image, Link, TextStyle, Color, DragHandle, AutoJoiner, Placeholder), configures slash-command menu state management (menuState, keyboard navigation: ArrowUp/Down/Enter), syncs isEditable via effect, and emits HTML via onChange.
Public Exports
src/shared/ui/rich-editor/index.ts, src/shared/ui/index.ts
RichEditor and RichEditorProps are exported from the rich-editor module and re-exported in the shared UI barrel.
Storybook Documentation
src/shared/ui/rich-editor/rich-editor.stories.tsx, src/shared/ui/input/input.stories.tsx
Rich-editor Storybook stories cover Default, WithContent, ReadOnly, PortfolioPlaceholder, and NoticePlaceholder variants; input stories icon import path updated to relative import.

Sequence Diagram

sequenceDiagram
    participant User
    participant RichEditor as RichEditor
    participant Tiptap as Tiptap Editor
    participant SlashMenu as SlashCommand<br/>Menu
    
    User->>RichEditor: Type "/" character
    RichEditor->>Tiptap: "/" triggers suggestion
    Tiptap->>RichEditor: onUpdate fires with/"query"
    RichEditor->>RichEditor: Filter & populate<br/>menuState items
    RichEditor->>SlashMenu: Render with items &<br/>selectedIndex=0
    SlashMenu->>SlashMenu: Position menu &<br/>scroll to selection
    
    User->>SlashMenu: Press ArrowDown
    SlashMenu->>SlashMenu: Update selectedIndex
    
    User->>SlashMenu: Press Enter
    SlashMenu->>SlashMenu: Execute selected<br/>command
    SlashMenu->>RichEditor: Call onSelect(item)
    RichEditor->>Tiptap: command({ editor, range })
    Tiptap->>RichEditor: Insert block &<br/>clear menuState
    RichEditor->>User: Render updated content
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

Suggested Labels

enhancement

Suggested Reviewers

  • jaeu5325
  • 1-J-1
  • sebeeeen

Poem

🐰 A rabbit hops through Tiptap's commands so grand,
With slashes and headings arranged hand in hand,
Seven icons gleam bright in the editor's glow,
Menu items dance as the keystrokes flow.
Rich editing magic—/adventure awaits! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly references issue #106 and accurately summarizes the main change: implementing a Novel-style slash command RichEditor component with the required UI/UX.
Description check ✅ Passed The PR description follows the template structure with all required sections: 'What is this PR?', 'Changes', 'Background/Context', and 'Checklist'. All key implementation details are documented.
Linked Issues check ✅ Passed All coding objectives from issue #106 are met: slash command UX implementation, 8 command types, Tiptap extensions integration, keyboard navigation, read-only mode support, icon additions, and Storybook stories.
Out of Scope Changes check ✅ Passed Changes to modal stories and input stories import paths are minor refactoring related to the overall rich-editor module integration. All changes support the primary objective of implementing the RichEditor component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/rich-editor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 4 minutes and 12 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@kimsman06 kimsman06 self-assigned this May 4, 2026
@kimsman06 kimsman06 linked an issue May 4, 2026 that may be closed by this pull request
7 tasks
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
src/shared/ui/icons/index.tsx (1)

562-753: ⚡ Quick win

Consider defaulting SVG icons to aria-hidden="true".

None of the new icons (nor the existing ones) suppress screen-reader announcement by default. When an icon appears alongside visible text — as it will inside the slash-command menu — screen readers may still announce the <svg> element. Because {...props} is spread last, callers can already override this, but the burden falls on every use-site.

A low-friction fix is to set aria-hidden="true" on the <svg> root of each new icon (and existing ones, ideally as a follow-up sweep):

♻️ Example for Heading1Icon (apply the same pattern to all new icons)
 export const Heading1Icon: React.FC<IconProps> = ({ size = 20, ...props }) => (
   <svg
     width={size}
     height={size}
     viewBox="0 0 20 20"
     fill="none"
     xmlns="http://www.w3.org/2000/svg"
+    aria-hidden="true"
     {...props}
   >

The {...props} spread still lets individual call-sites override with aria-hidden={false} + an explicit aria-label when an icon is used standalone.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/shared/ui/icons/index.tsx` around lines 562 - 753, The SVG icons
(Heading1Icon, Heading2Icon, Heading3Icon, ListBulletIcon, ListOrderedIcon,
QuoteIcon, CodeIcon) should default to aria-hidden="true" to prevent unnecessary
screen-reader announcements; update each component's <svg> root to include
aria-hidden="true" (keeping the existing {...props} spread so callers can
override with aria-hidden={false} and an aria-label when needed).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/shared/ui/rich-editor/rich-editor.tsx`:
- Around line 104-112: The command handler currently calls window.prompt() after
deleting the selection and passes unvalidated input to setImage; change it to
prompt before mutating the editor and add a minimal URL guard: extract the
prompt into a small helper (e.g., promptForImageUrl) so it can be mocked/tested
and feature-detected for sandboxed iframes, validate the returned value
(non-empty, reject javascript: scheme, require http/https or a safe data:
pattern) and only then call editor.chain().focus().deleteRange(range).setImage({
src: url }).run(); ensure you handle null/empty from the prompt by leaving the
editor untouched.
- Around line 241-243: The onUpdate callback passed into useEditor currently
closes over the initial onChange prop (onUpdate: ({ editor }) => {
onChange?.(editor.getHTML()); }), so later prop updates are ignored; fix this by
storing the latest onChange in a ref (e.g., onChangeRef) updated inside a
useEffect and call onChangeRef.current?.(editor.getHTML()) inside the useEditor
onUpdate handler so the editor always invokes the most recent onChange; update
references to onChange in useEditor/onUpdate to use the ref instead of the prop
directly.
- Line 172: Link.configure({ openOnClick: !isEditable }) captures isEditable at
initialization so links remain non-clickable when isEditable later changes;
instead set Link.configure({ openOnClick: false }) so it never freezes behavior,
and in the editor instance override click handling (use editorProps.handleClick
or handleClickOn) to detect current editor.isEditable (or the prop isEditable)
and manually open the link when the editor is read-only; keep the existing
useEffect that calls editor.setEditable(isEditable) and ensure the click handler
uses editor.getAttributes / node attrs to resolve and open the href when
appropriate.

In `@src/shared/ui/rich-editor/slash-command-menu.tsx`:
- Around line 56-84: Change the ARIA roles from a listbox/option pattern to a
menu/menuitem pattern: update the container that currently uses role="listbox"
(the div using menuClasses and positionStyle) to role="menu" and change each
item button that currently sets role="option" to role="menuitem"; keep the
existing selection handling (selectedIndex, aria-selected) or replace
aria-selected with aria-current/aria-checked only if semantically appropriate
for your menu items, and ensure itemRefs, getItemClasses, items, and onSelect
logic remain intact so keyboard focus and selection behavior are preserved.

---

Nitpick comments:
In `@src/shared/ui/icons/index.tsx`:
- Around line 562-753: The SVG icons (Heading1Icon, Heading2Icon, Heading3Icon,
ListBulletIcon, ListOrderedIcon, QuoteIcon, CodeIcon) should default to
aria-hidden="true" to prevent unnecessary screen-reader announcements; update
each component's <svg> root to include aria-hidden="true" (keeping the existing
{...props} spread so callers can override with aria-hidden={false} and an
aria-label when needed).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 162cf509-f1af-4de6-9b25-496b288316b1

📥 Commits

Reviewing files that changed from the base of the PR and between 07191ce and 9e80dfc.

📒 Files selected for processing (9)
  • src/shared/ui/icons/index.tsx
  • src/shared/ui/index.ts
  • src/shared/ui/input/input.stories.tsx
  • src/shared/ui/modal/modal.stories.tsx
  • src/shared/ui/rich-editor/index.ts
  • src/shared/ui/rich-editor/rich-editor.stories.tsx
  • src/shared/ui/rich-editor/rich-editor.tsx
  • src/shared/ui/rich-editor/slash-command-menu.tsx
  • src/shared/ui/rich-editor/slash-command.ts

Comment thread src/shared/ui/rich-editor/rich-editor.tsx
Comment thread src/shared/ui/rich-editor/rich-editor.tsx Outdated
Comment thread src/shared/ui/rich-editor/rich-editor.tsx
Comment thread src/shared/ui/rich-editor/slash-command-menu.tsx Outdated
Copy link
Copy Markdown
Member

@sebeeeen sebeeeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고많으셨습니다!!

@kimsman06 kimsman06 merged commit eb21c5f into dev May 7, 2026
1 check passed
@sebeeeen sebeeeen deleted the feat/rich-editor branch May 25, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Novel 스타일 슬래시 커맨드 RichEditor 구현

2 participants