pds-dev-kit-web 2.2.315 → 2.2.317-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,209 +0,0 @@
1
- import { Editor } from '@tinymce/tinymce-react';
2
- import { useRef, useEffect, useMemo } from 'react';
3
- import { useTranslation } from 'react-i18next';
4
- import tinymce from 'tinymce';
5
- import 'tinymce/icons/default';
6
- import 'tinymce/models/dom';
7
- import 'tinymce/plugins/advlist';
8
- import 'tinymce/plugins/anchor';
9
- import 'tinymce/plugins/autolink';
10
- import 'tinymce/plugins/charmap';
11
- import 'tinymce/plugins/code';
12
- import 'tinymce/plugins/fullscreen';
13
- import 'tinymce/plugins/image';
14
- import 'tinymce/plugins/insertdatetime';
15
- import 'tinymce/plugins/link';
16
- import 'tinymce/plugins/lists';
17
- import 'tinymce/plugins/media';
18
- import 'tinymce/plugins/preview';
19
- import 'tinymce/plugins/searchreplace';
20
- import 'tinymce/plugins/table';
21
- import 'tinymce/plugins/visualblocks';
22
- import 'tinymce/skins/content/default/content.min.css';
23
- import 'tinymce/skins/ui/oxide/content.min.css';
24
- import 'tinymce/skins/ui/oxide/skin.min.css';
25
- import 'tinymce/themes/silver';
26
-
27
- import { showDesktopAlertDialog } from '@core/overlay';
28
-
29
- import {
30
- PersonalizationTagCallback,
31
- setPersonalizationModalCallback,
32
- registerCustomTokensPlugin
33
- } from './personalization_tag_plugin';
34
- import './tinymce-toolbar.css';
35
-
36
- import type { Editor as TinyMCEEditor } from 'tinymce';
37
-
38
- type ImageUploadHandler = (file: File) => Promise<string>;
39
-
40
- type EditorProps = {
41
- initialContent?: string;
42
- onChange?: (content: string) => void;
43
- onOpenPersonalizationModal?: PersonalizationTagCallback;
44
- onImageUpload?: ImageUploadHandler;
45
- };
46
-
47
- // Register the custom plugin before any Editor component mounts
48
- registerCustomTokensPlugin(tinymce);
49
-
50
- export default function CustomTinyMCEEditor({
51
- initialContent,
52
- onChange,
53
- onOpenPersonalizationModal,
54
- onImageUpload
55
- }: EditorProps) {
56
- const { t } = useTranslation('translation');
57
- const editorRef = useRef<TinyMCEEditor | null>(null);
58
- const uploadedBlobsRef = useRef<Map<string, string>>(new Map());
59
- const isEditorReady = useRef(false);
60
-
61
- // Store initial content in ref so it doesn't change on re-renders
62
- const initialContentRef = useRef(initialContent);
63
-
64
- // Use refs to keep callbacks stable
65
- const onChangeRef = useRef(onChange);
66
- const onImageUploadRef = useRef(onImageUpload);
67
- const tRef = useRef(t);
68
-
69
- // Update refs when props change
70
- useEffect(() => {
71
- onChangeRef.current = onChange;
72
- }, [onChange]);
73
-
74
- useEffect(() => {
75
- onImageUploadRef.current = onImageUpload;
76
- }, [onImageUpload]);
77
-
78
- useEffect(() => {
79
- tRef.current = t;
80
- }, [t]);
81
-
82
- useEffect(() => {
83
- setPersonalizationModalCallback(onOpenPersonalizationModal || null);
84
- return () => {
85
- setPersonalizationModalCallback(null);
86
- };
87
- }, [onOpenPersonalizationModal]);
88
-
89
- const handleInit = (_evt: unknown, editor: TinyMCEEditor) => {
90
- editorRef.current = editor;
91
- isEditorReady.current = true;
92
- };
93
-
94
- // Use the official onEditorChange callback from @tinymce/tinymce-react
95
- const handleEditorChange = (content: string) => {
96
- onChangeRef.current?.(content);
97
- };
98
-
99
- // Memoize init object to prevent re-initialization
100
- const editorInit = useMemo(
101
- () => ({
102
- height: 500,
103
- menubar: false,
104
- statusbar: true,
105
- elementpath: false,
106
- branding: false,
107
- toolbar_mode: 'wrap' as const,
108
- plugins:
109
- 'advlist anchor autolink charmap code fullscreen image insertdatetime link lists media preview searchreplace table visualblocks customtokens',
110
- toolbar:
111
- 'blocks bold italic underline strikethrough | forecolor backcolor alignleft aligncenter alignright alignjustify outdent indent | numlist bullist blockquote insertTag link image media undo redo',
112
- skin: false,
113
- content_css: false,
114
- content_style: `
115
- body { font-family:Helvetica,Arial,sans-serif; font-size:16px; line-height: 1.5; overflow-wrap: break-word; word-break: break-word; word-wrap: break-word; }
116
- p { margin: 0; }
117
- a { color: #0066cc; text-decoration: underline; }
118
- img { max-width: 100%; height: auto; display: block; margin: 16px 0; border: none; object-fit: contain; }
119
- video, iframe { width: 100%; margin: 16px 0; padding: 0; border: none; display: block; max-width: 100%; }
120
- span[data-mce-object="video"], span[data-mce-object="iframe"] { display: block; width: 100%; margin: 16px 0; border: none; }
121
- span[data-mce-object]::before { content: ''; display: block; }
122
- span[data-mce-object]::after { content: ''; display: block; }
123
- .mce-object-video, .mce-object-iframe, .mce-preview-object { margin: 0; padding: 0; border: none; }
124
- .mce-preview-object > iframe { border: none; }
125
- table { width: 100%; margin: 16px 0; border: none; border-collapse: collapse; }
126
- .alert-warning { border-left: 5px solid #ffdd00; padding: 10px; background: #fff8e1; margin: 10px 0; border-radius: 4px; }
127
- `,
128
- automatic_uploads: true,
129
- images_reuse_filename: true,
130
- paste_data_images: true,
131
- media_live_embeds: true,
132
- images_upload_handler: (blobInfo: {
133
- blobUri: () => string;
134
- blob: () => Blob;
135
- filename: () => string;
136
- }): Promise<string> => {
137
- return new Promise((resolve, reject) => {
138
- const blobUri = blobInfo.blobUri();
139
-
140
- const existingUrl = uploadedBlobsRef.current.get(blobUri);
141
- if (existingUrl) {
142
- resolve(existingUrl);
143
- return;
144
- }
145
-
146
- if (!onImageUploadRef.current) {
147
- reject(new Error('No upload handler'));
148
- return;
149
- }
150
-
151
- const file = new File([blobInfo.blob()], blobInfo.filename(), {
152
- type: blobInfo.blob().type
153
- });
154
-
155
- onImageUploadRef
156
- .current(file)
157
- .then((url) => {
158
- uploadedBlobsRef.current.set(blobUri, url);
159
- resolve(url);
160
- })
161
- .catch((error) => {
162
- showDesktopAlertDialog({
163
- contentText: tRef.current('str_papp_image_upload_failed'),
164
- btnMode: 'tbtn_amount1',
165
- tBtn1Text: tRef.current('str_confirm')
166
- });
167
- reject(error);
168
- });
169
- });
170
- },
171
- // Additional event handlers for formatting changes that onEditorChange might miss
172
- setup: (editor: TinyMCEEditor) => {
173
- // Handle formatting commands - use setTimeout to ensure DOM is updated
174
- editor.on('ExecCommand', (e) => {
175
- // Only trigger for formatting-related commands
176
- const formattingCommands = [
177
- 'mceToggleFormat',
178
- 'Bold',
179
- 'Italic',
180
- 'Underline',
181
- 'Strikethrough',
182
- 'ForeColor',
183
- 'BackColor',
184
- 'FontSize',
185
- 'FormatBlock'
186
- ];
187
- if (formattingCommands.some((cmd) => e.command.includes(cmd))) {
188
- setTimeout(() => {
189
- const content = editor.getContent();
190
- onChangeRef.current?.(content);
191
- }, 10);
192
- }
193
- });
194
- }
195
- }),
196
- []
197
- );
198
-
199
- return (
200
- <div>
201
- <Editor
202
- onInit={handleInit}
203
- initialValue={initialContentRef.current}
204
- onEditorChange={handleEditorChange}
205
- init={editorInit}
206
- />
207
- </div>
208
- );
209
- }
@@ -1,43 +0,0 @@
1
- import { TinyMCE, Editor } from 'tinymce';
2
-
3
- export type PersonalizationTagCallback = (insertTag: (tag: string) => void) => void;
4
-
5
- let onOpenPersonalizationModalCallback: PersonalizationTagCallback | null = null;
6
-
7
- export function setPersonalizationModalCallback(callback: PersonalizationTagCallback | null) {
8
- onOpenPersonalizationModalCallback = callback;
9
- }
10
-
11
- /**
12
- * Registers the custom tokens plugin with the provided TinyMCE instance.
13
- * Must be called before the Editor component initializes.
14
- */
15
- export function registerCustomTokensPlugin(tinymceInstance: TinyMCE): void {
16
- // Prevent duplicate registration
17
- if (tinymceInstance.PluginManager.get('customtokens')) {
18
- return;
19
- }
20
-
21
- tinymceInstance.PluginManager.add('customtokens', (editor: Editor) => {
22
- editor.ui.registry.addIcon(
23
- 'merge-field',
24
- '<svg width="24" height="24" viewBox="0 0 24 24"><text x="4" y="17" font-size="14" font-weight="900" stroke="currentColor" stroke-width="0.5">{ }</text></svg>'
25
- );
26
-
27
- editor.ui.registry.addButton('insertTag', {
28
- tooltip: 'Insert Personalization Tag',
29
- icon: 'merge-field',
30
- onAction: () => {
31
- const insertTag = (tag: string) => {
32
- // Insert as plain text so it can be formatted like regular text
33
- editor.insertContent(tag);
34
- };
35
-
36
- if (onOpenPersonalizationModalCallback) {
37
- onOpenPersonalizationModalCallback(insertTag);
38
- }
39
- }
40
- });
41
- return { getMetadata: () => ({ name: 'Personalization Tag Plugin', url: '' }) };
42
- });
43
- }
@@ -1,13 +0,0 @@
1
- /* TinyMCE toolbar button size reduction */
2
- .tox .tox-tbtn {
3
- width: 25px;
4
- min-width: 25px;
5
- }
6
-
7
- .tox .tox-tbtn--select {
8
- width: auto !important;
9
- }
10
-
11
- .tox.tox-tinymce {
12
- z-index: 0 !important;
13
- }
@@ -1,57 +0,0 @@
1
- # [Refactoring] PDS RichTextEditor 기반 범용 이메일 에디터 구축 및 피처 종속 로직 분리
2
-
3
- ## 1. 진행 배경 및 목적 (Background & Objective)
4
- * **배경**: 현재 제품(Product) 프로젝트에는 특정 이메일 발송 피처를 위해 자체적으로 구현한 `CustomTinyMCEEditor`(`.reference/OldEmailRichTextEditor/CustomTinyMCEEditor.tsx`)가 존재합니다. 이번 통합 리팩토링을 위해 해당 컴포넌트를 임시로 PDS(`pds-dev-kit`) 프로젝트로 가져온 상태입니다.
5
- * **문제점**: `CustomTinyMCEEditor`는 범용적인 이메일 에디터가 아니라 **특정 피처의 비즈니스 로직(예: 특정 모달 호출, 고유 이미지 처리 등)에 강하게 결합**되어 만들어졌습니다. 이를 그대로 PDS 라이브러리의 공통 컴포넌트로 편입시킬 경우 도메인 의존성이 생기는 문제가 발생합니다.
6
- * **목적**:
7
- 1. `CustomTinyMCEEditor`에 혼재된 **'범용 이메일 에디터로서의 내부 로직'**과 **'특정 피처를 위한 외부 로직'**을 완벽하게 분리(Decoupling)합니다.
8
- 2. PDS의 표준인 `RichTextEditor`를 유연하게 확장하여, 범용으로 사용할 수 있는 래퍼 컴포넌트 `EmailRichTextEditor`를 PDS 내부에 구축합니다.
9
- 3. 제품(Consumer) 측에서는 이 `EmailRichTextEditor`를 가져다 쓰되, 도메인 특화 파트(모달, 업로드 등)는 Props와 콜백을 통해 주입(Injection)하도록 제어의 역전(IoC) 구조를 만듭니다.
10
-
11
- ## 2. 핵심 구현 전략 (Core Strategy)
12
- * **관심사의 분리 (Separation of Concerns)**
13
- * **PDS (EmailRichTextEditor)의 책임**: 이메일용 컴팩트 툴바 UI, 이메일에 적합한 Content Style(인라인 CSS 호환), 이메일 작성에 필요한 공통 플러그인 렌더링.
14
- * **제품 프로젝트(Consumer)의 책임**: 이미지 업로드 API 통신, 특정 피처용 개인화 태그(치환 태그) 삽입 모달의 렌더링 및 제어 로직 구현 후 주입.
15
- * **확장성 확보 (initOptions 도입)**: `RichTextEditor`가 모든 에디터 옵션을 Prop으로 들고 있지 않게 하고, TinyMCE의 `init` 설정을 소비자가 통째로 병합할 수 있도록 `initOptions` Prop을 신설합니다.
16
-
17
- ---
18
-
19
- ## 3. 상세 요구사항 (Detailed Requirements)
20
-
21
- ### Task 1. `RichTextEditor` 확장 및 하위 호환성 보장 (`src/desktop/components/RichTextEditor/RichTextEditor.tsx`)
22
- PDS 전체에서 사용되는 표준 에디터이므로 레거시 화면이 깨지지 않는 것이 가장 중요합니다.
23
- * **Prop 확장**
24
- * `initOptions?: Parameters<TinyMCE['init']>[0];`: TinyMCE 고유 설정을 주입받습니다. 컴포넌트 내부의 기본 `init` 설정과 병합하되, `initOptions`의 값이 우선순위를 가지도록 구현하세요 (`...initOptions`).
25
- * `onSetup?: (editor: TinyMCEEditor) => void;`: 에디터 초기화(Setup) 시점에 외부에서 이벤트를 바인딩할 수 있도록 콜백을 엽니다.
26
- * `isCompactToolbar?: boolean;`: `true` 시 이메일 에디터 특유의 좁은 간격/작은 버튼 스타일이 적용되도록 CSS를 조건부 처리하세요.
27
- * **기본 설정 정비**
28
- * `automatic_uploads`, `images_reuse_filename`, `paste_data_images`, `media_live_embeds` 등을 기본 `init` 속성으로 명시하세요.
29
-
30
- ### Task 2. `EmailRichTextEditor` 범용 래퍼 구축 (`src/desktop/components/RichTextEditor/EmailRichTextEditor.tsx`)
31
- PDS 라이브러리로서 제공될 순수 **'이메일 전용 텍스트 에디터'**입니다. 특정 비즈니스 로직은 철저히 배제하세요.
32
- * `RichTextEditor`를 반환하는 Wrapper 형태로 구현합니다.
33
- * **기본 이메일 설정 주입 (`initOptions`)**
34
- * 범용 이메일 에디터에 필요한 상수들 (`EMAIL_PLUGINS`, `EMAIL_TOOLBAR`, `EMAIL_CONTENT_STYLE`)을 선언하고 `initOptions`를 통해 `RichTextEditor`에 주입합니다.
35
- * 이미지 업로드 캐싱 로직(드래그 앤 드롭 시 기존 업로드 Blob 재사용)은 에디터의 범용 UI/UX 편의 기능이므로, 래퍼 컴포넌트 내 `images_upload_handler`에 공통으로 구현합니다. (실제 업로드 통신 함수인 `onImageUpload`는 Props로 받아 실행)
36
- * **커스텀 이벤트 브릿지 (`onSetup`)**
37
- * 포맷팅 변경 시점(`Bold`, `Italic` 등 `ExecCommand` 발생)에 강제로 `onChange`를 지연 트리거 시키는 동기화 로직을 주입합니다.
38
- * 에디터 기본 높이(`height`)는 기존 UI와 동일하게 `500`으로 고정합니다.
39
-
40
- ### Task 3. 외부 도메인 로직 분리 설계 (`personalization_tag_plugin.ts` 리팩토링)
41
- 제품의 특정 피처에서만 쓰이던 '개인화 태그(치환 태그)' 플러그인을 범용 에디터에 올바르게 결합하기 위한 작업입니다.
42
- * **글로벌 등록 폐기**: `tinymce.PluginManager`에 의존하던 전역 등록 방식을 버리고, 특정 에디터 인스턴스에만 적용되도록 변경합니다.
43
- * **Setup 콜백 생성 함수로 변경**
44
- * `getPersonalizationSetup(onOpenPersonalizationModal?: Callback)` 형태의 팩토리 함수로 리팩토링하세요.
45
- * 이 함수는 `EmailRichTextEditor`가 렌더링 될 때, 외부(제품 프로젝트)로부터 `onOpenPersonalizationModal` 콜백을 주입받아 모달 트리거 로직을 완성한 뒤, TinyMCE의 `setup` 시점에 실행할 함수를 반환해야 합니다.
46
-
47
- ---
48
-
49
- ## 4. 완료 조건 및 검증 (Acceptance Criteria)
50
-
51
- 1. **관심사 분리 확인**: PDS 내의 `EmailRichTextEditor` 코드를 리뷰했을 때, 특정 제품의 모달 이름, API 엔드포인트 등의 비즈니스 종속 코드가 단 한 줄도 없어야 합니다. 오직 PDS의 컴포넌트로서 Props Interface만 제공해야 합니다.
52
- 2. **하위 호환성 (Regression Free)**: 기존 `RichTextEditor`를 사용하는 일반 화면에서 런타임 에러, TypeScript 인터페이스 에러, 스타일 깨짐이 없어야 합니다.
53
- 3. **기능 검증**: 제품 프로젝트에서 `EmailRichTextEditor`를 마운트했을 때,
54
- * 기존과 동일한 컴팩트 툴바 UI가 노출될 것
55
- * `{ }` (개인화 태그) 아이콘 클릭 시, 앱에서 주입한 전용 모달이 정상적으로 호출될 것
56
- * 이미지 업로드, 텍스트 포맷팅 등이 기존 `CustomTinyMCEEditor` 환경과 100% 동일하게 동작할 것
57
- 4. **마무리**: 통합 검증 통과 시 `.reference/OldEmailRichTextEditor` 참고용 폴더를 안전하게 삭제합니다.