|
1 | | -import { Node, mergeAttributes } from '@tiptap/core'; |
2 | | -import { ReactNodeViewRenderer } from '@tiptap/react'; |
3 | | -import PaywallComponent from './PaywallComponent'; // React 컴포넌트로 렌더링 |
| 1 | +import { Node } from '@tiptap/core'; |
4 | 2 |
|
5 | 3 | const CustomPaywall = Node.create({ |
6 | 4 | name: 'paywall', |
7 | 5 |
|
8 | | - group: 'block', // 블록 요소로 처리 |
9 | | - atom: true, // 독립적 요소 |
| 6 | + group: 'block', |
| 7 | + atom: true, |
10 | 8 |
|
11 | 9 | addAttributes() { |
12 | 10 | return { |
| 11 | + alignment: { default: 'mr-auto ml-0' }, |
13 | 12 | title: { default: '프리미엄 구독자 전용 콘텐츠입니다.' }, |
14 | 13 | description: { |
15 | 14 | default: '모아가이드 구독으로 더 많은 콘텐츠를 만나보세요!', |
16 | 15 | }, |
17 | 16 | buttonText: { default: '프리미엄 구독하기' }, |
18 | 17 | info: { |
19 | | - default: '콘텐츠 이용권한이 없는 경우 여기까지만 확인 가능합니다.', |
20 | | - }, |
21 | | - brInfo: { |
22 | | - default: '콘텐츠 판매 설정에 따라 문구 및 버튼이 변경될 수 있습니다.', |
| 18 | + default: `콘텐츠 이용권한이 없는 경우 여기까지만 확인 가능합니다.\n콘텐츠 판매 설정에 따라 문구 및 버튼이 변경될 수 있습니다.`, |
23 | 19 | }, |
24 | 20 | }; |
25 | 21 | }, |
26 | 22 |
|
27 | 23 | parseHTML() { |
28 | 24 | return [ |
29 | 25 | { |
30 | | - tag: 'div.se_paywall', |
| 26 | + tag: 'div.se-section.se-section-custom.se-l-default.se-section-align-left', |
| 27 | + getAttrs: (element) => { |
| 28 | + const alignment = element.classList.contains( |
| 29 | + 'se-section-align-center', |
| 30 | + ) |
| 31 | + ? 'mx-auto' |
| 32 | + : element.classList.contains('se-section-align-right') |
| 33 | + ? 'ml-auto mr-0' |
| 34 | + : 'mr-auto ml-0'; |
| 35 | + |
| 36 | + const paywallElement = element.querySelector('.se_paywall'); |
| 37 | + if (!paywallElement) { |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + const title = |
| 42 | + paywallElement.querySelector('.se_paywall_title')?.textContent || |
| 43 | + ''; |
| 44 | + const description = |
| 45 | + paywallElement.querySelector('.se_paywall_desc')?.textContent || ''; |
| 46 | + const buttonText = |
| 47 | + paywallElement.querySelector('.se_paywall_subscribe') |
| 48 | + ?.textContent || ''; |
| 49 | + const info = Array.from( |
| 50 | + paywallElement.querySelector('.se_paywall_info')?.childNodes || [], |
| 51 | + ) |
| 52 | + .map((node) => (node.nodeName === 'BR' ? '\n' : node.textContent)) |
| 53 | + .join(''); |
| 54 | + |
| 55 | + return { alignment, title, description, buttonText, info }; |
| 56 | + }, |
31 | 57 | }, |
32 | 58 | ]; |
33 | 59 | }, |
34 | 60 |
|
35 | 61 | renderHTML({ HTMLAttributes }) { |
| 62 | + const { alignment, title, description, buttonText, info } = HTMLAttributes; |
| 63 | + |
36 | 64 | return [ |
37 | 65 | 'div', |
38 | | - mergeAttributes(HTMLAttributes, { class: 'se_paywall' }), |
| 66 | + { |
| 67 | + class: `block mx-[-20px] relative ${alignment}`, |
| 68 | + }, |
39 | 69 | [ |
40 | 70 | 'div', |
41 | | - { class: 'se_paywall_text' }, |
42 | | - ['strong', { class: 'se_paywall_title' }, HTMLAttributes.title], |
43 | | - ['p', { class: 'se_paywall_desc' }, HTMLAttributes.description], |
44 | | - ['a', { class: 'se_paywall_subscribe' }, HTMLAttributes.buttonText], |
| 71 | + { |
| 72 | + class: `p-[28px_20px_0] tracking-[-0.5px] text-center`, |
| 73 | + }, |
| 74 | + [ |
| 75 | + 'div', |
| 76 | + { class: 'px-[11px] py-[20px] text-[#303038]' }, |
| 77 | + ['strong', { class: 'text-[18px] leading-[24px]' }, title], |
| 78 | + [ |
| 79 | + 'p', |
| 80 | + { class: 'mt-[3px] text-[14px] leading-[20px] opacity-75' }, |
| 81 | + description, |
| 82 | + ], |
| 83 | + [ |
| 84 | + 'a', |
| 85 | + { |
| 86 | + class: |
| 87 | + 'overflow-hidden block mt-[31px] px-[15px] py-[13px] text-[17px] font-semibold leading-[20px] text-[#222] tracking-[-0.5px] rounded-[3px] shadow-md border border-[rgba(255,255,255,0.09)] bg-gradient-to-r from-[#e6b459] to-[#e9a750]', |
| 88 | + }, |
| 89 | + buttonText, |
| 90 | + ], |
| 91 | + ], |
| 92 | + [ |
| 93 | + 'p', |
| 94 | + { |
| 95 | + class: |
| 96 | + 'pt-[20px] pb-[18px] text-[14px] leading-[20px] text-[#999] border-t border-[rgba(0,0,0,0.1)]', |
| 97 | + }, |
| 98 | + ...info |
| 99 | + .split('\n') |
| 100 | + .flatMap((line: string, index: number, array: string[]) => |
| 101 | + index < array.length - 1 ? [line, ['br']] : [line], |
| 102 | + ), |
| 103 | + ], |
45 | 104 | ], |
46 | | - ['p', { class: 'se_paywall_info' }, HTMLAttributes.info], |
47 | 105 | ]; |
48 | 106 | }, |
49 | | - |
50 | | - addNodeView() { |
51 | | - return ReactNodeViewRenderer(PaywallComponent); // React 컴포넌트와 연결 |
52 | | - }, |
53 | 107 | }); |
54 | 108 |
|
55 | 109 | export default CustomPaywall; |
0 commit comments