Spaces:
Sleeping
Sleeping
Upload 61 files
Browse files
components/CodeBlockComponent.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import React, { useState, useEffect, useRef } from 'react';
|
| 2 |
import { NodeViewWrapper, NodeViewContent, NodeViewProps } from '@tiptap/react';
|
| 3 |
-
import { Copy, Check, Download, Pencil, ChevronDown, ChevronUp } from 'lucide-react';
|
| 4 |
|
| 5 |
export const CodeBlockComponent: React.FC<NodeViewProps> = (props) => {
|
| 6 |
const [copied, setCopied] = useState(false);
|
|
@@ -109,6 +109,14 @@ export const CodeBlockComponent: React.FC<NodeViewProps> = (props) => {
|
|
| 109 |
const handleClick = (e: React.MouseEvent) => {
|
| 110 |
if (e.detail === 3 && props.editor.isEditable) {
|
| 111 |
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
const event = new CustomEvent('block-triple-click', {
|
| 113 |
detail: { type: 'code', pos: props.getPos() },
|
| 114 |
bubbles: true
|
|
@@ -157,14 +165,24 @@ export const CodeBlockComponent: React.FC<NodeViewProps> = (props) => {
|
|
| 157 |
</div>
|
| 158 |
<div className="flex items-center gap-2">
|
| 159 |
{props.editor.isEditable && (
|
| 160 |
-
<
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
)}
|
| 169 |
<button
|
| 170 |
onClick={handleDownload}
|
|
|
|
| 1 |
import React, { useState, useEffect, useRef } from 'react';
|
| 2 |
import { NodeViewWrapper, NodeViewContent, NodeViewProps } from '@tiptap/react';
|
| 3 |
+
import { Copy, Check, Download, Pencil, ChevronDown, ChevronUp, Settings } from 'lucide-react';
|
| 4 |
|
| 5 |
export const CodeBlockComponent: React.FC<NodeViewProps> = (props) => {
|
| 6 |
const [copied, setCopied] = useState(false);
|
|
|
|
| 109 |
const handleClick = (e: React.MouseEvent) => {
|
| 110 |
if (e.detail === 3 && props.editor.isEditable) {
|
| 111 |
e.preventDefault();
|
| 112 |
+
handleOpenSettings(e);
|
| 113 |
+
}
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
const handleOpenSettings = (e: React.MouseEvent) => {
|
| 117 |
+
e.preventDefault();
|
| 118 |
+
e.stopPropagation();
|
| 119 |
+
if (props.editor.isEditable) {
|
| 120 |
const event = new CustomEvent('block-triple-click', {
|
| 121 |
detail: { type: 'code', pos: props.getPos() },
|
| 122 |
bubbles: true
|
|
|
|
| 165 |
</div>
|
| 166 |
<div className="flex items-center gap-2">
|
| 167 |
{props.editor.isEditable && (
|
| 168 |
+
<>
|
| 169 |
+
<button
|
| 170 |
+
onClick={(e) => handleOpenSettings(e)}
|
| 171 |
+
contentEditable={false}
|
| 172 |
+
className="p-1.5 rounded-md transition-all duration-200 hover:bg-white/10 text-zinc-400 hover:text-white"
|
| 173 |
+
title="Configurar Estilo"
|
| 174 |
+
>
|
| 175 |
+
<Settings size={14} />
|
| 176 |
+
</button>
|
| 177 |
+
<button
|
| 178 |
+
onClick={() => setIsEditingName(true)}
|
| 179 |
+
contentEditable={false}
|
| 180 |
+
className="p-1.5 rounded-md transition-all duration-200 hover:bg-white/10 text-zinc-400 hover:text-white"
|
| 181 |
+
title="Editar nombre"
|
| 182 |
+
>
|
| 183 |
+
<Pencil size={14} />
|
| 184 |
+
</button>
|
| 185 |
+
</>
|
| 186 |
)}
|
| 187 |
<button
|
| 188 |
onClick={handleDownload}
|
components/DataForm.tsx
CHANGED
|
@@ -68,14 +68,21 @@ export const DataForm: React.FC<DataFormProps> = ({ initialData, onSave, onCance
|
|
| 68 |
selectedIcon={icon}
|
| 69 |
onSelect={setIcon}
|
| 70 |
/>
|
| 71 |
-
<
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
</div>
|
| 80 |
</div>
|
| 81 |
|
|
|
|
| 68 |
selectedIcon={icon}
|
| 69 |
onSelect={setIcon}
|
| 70 |
/>
|
| 71 |
+
<div className="w-full bg-background border border-white/10 rounded-lg overflow-hidden focus-within:border-primary focus-within:ring-1 focus-within:ring-primary transition-colors">
|
| 72 |
+
<TipTapEditor
|
| 73 |
+
content={title}
|
| 74 |
+
onUpdate={(content) => {
|
| 75 |
+
if (typeof content === 'string') {
|
| 76 |
+
setTitle(content);
|
| 77 |
+
}
|
| 78 |
+
}}
|
| 79 |
+
isEditable={true}
|
| 80 |
+
showToolbarOnFocus={true}
|
| 81 |
+
className="px-4 py-2 min-h-[50px] text-lg"
|
| 82 |
+
dense={true}
|
| 83 |
+
minimalMode={true}
|
| 84 |
+
/>
|
| 85 |
+
</div>
|
| 86 |
</div>
|
| 87 |
</div>
|
| 88 |
|
components/EditorToolbar.tsx
CHANGED
|
@@ -239,7 +239,8 @@ export const EditorToolbar: React.FC<EditorToolbarProps> = ({
|
|
| 239 |
|
| 240 |
const handleClearFormatting = (e: React.MouseEvent) => {
|
| 241 |
e.preventDefault();
|
| 242 |
-
|
|
|
|
| 243 |
};
|
| 244 |
|
| 245 |
const handleImageUploadClick = () => {
|
|
@@ -361,18 +362,21 @@ export const EditorToolbar: React.FC<EditorToolbarProps> = ({
|
|
| 361 |
<ToolbarButton
|
| 362 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleHeading({ level: 1 }).run())}
|
| 363 |
isActive={editor.isActive('heading', { level: 1 })}
|
|
|
|
| 364 |
icon={<Heading1 size={18} />}
|
| 365 |
title="Título 1"
|
| 366 |
/>
|
| 367 |
<ToolbarButton
|
| 368 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleHeading({ level: 2 }).run())}
|
| 369 |
isActive={editor.isActive('heading', { level: 2 })}
|
|
|
|
| 370 |
icon={<Heading2 size={18} />}
|
| 371 |
title="Título 2"
|
| 372 |
/>
|
| 373 |
<ToolbarButton
|
| 374 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().setParagraph().run())}
|
| 375 |
isActive={editor.isActive('paragraph')}
|
|
|
|
| 376 |
icon={<Pilcrow size={18} />}
|
| 377 |
title="Párrafo"
|
| 378 |
/>
|
|
@@ -382,12 +386,14 @@ export const EditorToolbar: React.FC<EditorToolbarProps> = ({
|
|
| 382 |
<ToolbarButton
|
| 383 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleBold().run())}
|
| 384 |
isActive={editor.isActive('bold')}
|
|
|
|
| 385 |
icon={<Bold size={18} />}
|
| 386 |
title="Negrita"
|
| 387 |
/>
|
| 388 |
<ToolbarButton
|
| 389 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleItalic().run())}
|
| 390 |
isActive={editor.isActive('italic')}
|
|
|
|
| 391 |
icon={<Italic size={18} />}
|
| 392 |
title="Cursiva"
|
| 393 |
/>
|
|
@@ -401,12 +407,14 @@ export const EditorToolbar: React.FC<EditorToolbarProps> = ({
|
|
| 401 |
<ToolbarButton
|
| 402 |
onMouseDown={handleCodeClick}
|
| 403 |
isActive={editor.isActive('code') && editor.getAttributes('code').showBackground !== false}
|
|
|
|
| 404 |
icon={<Code size={18} />}
|
| 405 |
title="Código Inline"
|
| 406 |
/>
|
| 407 |
<ToolbarButton
|
| 408 |
onMouseDown={handleCardCodeClick}
|
| 409 |
isActive={editor.isActive('code') && editor.getAttributes('code').showBackground === false}
|
|
|
|
| 410 |
icon={<Terminal size={18} />}
|
| 411 |
title="Texto Estilo Tarjeta"
|
| 412 |
/>
|
|
@@ -422,6 +430,7 @@ export const EditorToolbar: React.FC<EditorToolbarProps> = ({
|
|
| 422 |
}).run();
|
| 423 |
}}
|
| 424 |
isActive={editor.isActive('codeBlock')}
|
|
|
|
| 425 |
icon={<FileCode size={18} />}
|
| 426 |
title="Bloque de Código"
|
| 427 |
/>
|
|
@@ -495,12 +504,14 @@ export const EditorToolbar: React.FC<EditorToolbarProps> = ({
|
|
| 495 |
<ToolbarButton
|
| 496 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleBulletList().run())}
|
| 497 |
isActive={editor.isActive('bulletList')}
|
|
|
|
| 498 |
icon={<List size={18} />}
|
| 499 |
title="Lista con viñetas"
|
| 500 |
/>
|
| 501 |
<ToolbarButton
|
| 502 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleOrderedList().run())}
|
| 503 |
isActive={editor.isActive('orderedList')}
|
|
|
|
| 504 |
icon={<ListOrdered size={18} />}
|
| 505 |
title="Lista numerada"
|
| 506 |
/>
|
|
|
|
| 239 |
|
| 240 |
const handleClearFormatting = (e: React.MouseEvent) => {
|
| 241 |
e.preventDefault();
|
| 242 |
+
// Solo eliminamos marcas para no romper estructura de listas o código
|
| 243 |
+
editor.chain().focus().unsetAllMarks().run();
|
| 244 |
};
|
| 245 |
|
| 246 |
const handleImageUploadClick = () => {
|
|
|
|
| 362 |
<ToolbarButton
|
| 363 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleHeading({ level: 1 }).run())}
|
| 364 |
isActive={editor.isActive('heading', { level: 1 })}
|
| 365 |
+
disabled={!editor.can().toggleHeading({ level: 1 })}
|
| 366 |
icon={<Heading1 size={18} />}
|
| 367 |
title="Título 1"
|
| 368 |
/>
|
| 369 |
<ToolbarButton
|
| 370 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleHeading({ level: 2 }).run())}
|
| 371 |
isActive={editor.isActive('heading', { level: 2 })}
|
| 372 |
+
disabled={!editor.can().toggleHeading({ level: 2 })}
|
| 373 |
icon={<Heading2 size={18} />}
|
| 374 |
title="Título 2"
|
| 375 |
/>
|
| 376 |
<ToolbarButton
|
| 377 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().setParagraph().run())}
|
| 378 |
isActive={editor.isActive('paragraph')}
|
| 379 |
+
disabled={!editor.can().setParagraph()}
|
| 380 |
icon={<Pilcrow size={18} />}
|
| 381 |
title="Párrafo"
|
| 382 |
/>
|
|
|
|
| 386 |
<ToolbarButton
|
| 387 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleBold().run())}
|
| 388 |
isActive={editor.isActive('bold')}
|
| 389 |
+
disabled={!editor.can().toggleBold()}
|
| 390 |
icon={<Bold size={18} />}
|
| 391 |
title="Negrita"
|
| 392 |
/>
|
| 393 |
<ToolbarButton
|
| 394 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleItalic().run())}
|
| 395 |
isActive={editor.isActive('italic')}
|
| 396 |
+
disabled={!editor.can().toggleItalic()}
|
| 397 |
icon={<Italic size={18} />}
|
| 398 |
title="Cursiva"
|
| 399 |
/>
|
|
|
|
| 407 |
<ToolbarButton
|
| 408 |
onMouseDown={handleCodeClick}
|
| 409 |
isActive={editor.isActive('code') && editor.getAttributes('code').showBackground !== false}
|
| 410 |
+
disabled={!editor.can().setMark('code')}
|
| 411 |
icon={<Code size={18} />}
|
| 412 |
title="Código Inline"
|
| 413 |
/>
|
| 414 |
<ToolbarButton
|
| 415 |
onMouseDown={handleCardCodeClick}
|
| 416 |
isActive={editor.isActive('code') && editor.getAttributes('code').showBackground === false}
|
| 417 |
+
disabled={!editor.can().setMark('code')}
|
| 418 |
icon={<Terminal size={18} />}
|
| 419 |
title="Texto Estilo Tarjeta"
|
| 420 |
/>
|
|
|
|
| 430 |
}).run();
|
| 431 |
}}
|
| 432 |
isActive={editor.isActive('codeBlock')}
|
| 433 |
+
disabled={!editor.can().setCodeBlock()}
|
| 434 |
icon={<FileCode size={18} />}
|
| 435 |
title="Bloque de Código"
|
| 436 |
/>
|
|
|
|
| 504 |
<ToolbarButton
|
| 505 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleBulletList().run())}
|
| 506 |
isActive={editor.isActive('bulletList')}
|
| 507 |
+
disabled={!editor.can().toggleBulletList()}
|
| 508 |
icon={<List size={18} />}
|
| 509 |
title="Lista con viñetas"
|
| 510 |
/>
|
| 511 |
<ToolbarButton
|
| 512 |
onMouseDown={(e) => handleAction(e, () => editor.chain().focus().toggleOrderedList().run())}
|
| 513 |
isActive={editor.isActive('orderedList')}
|
| 514 |
+
disabled={!editor.can().toggleOrderedList()}
|
| 515 |
icon={<ListOrdered size={18} />}
|
| 516 |
title="Lista numerada"
|
| 517 |
/>
|
components/QuoteComponent.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import React, { useState, useRef, useEffect } from 'react';
|
| 2 |
import { NodeViewWrapper, NodeViewContent, NodeViewProps } from '@tiptap/react';
|
| 3 |
-
import { Copy, Check, Download, ChevronDown, ChevronUp } from 'lucide-react';
|
| 4 |
import { DownloadButton } from './DownloadButton';
|
| 5 |
|
| 6 |
export const QuoteComponent: React.FC<NodeViewProps> = (props) => {
|
|
@@ -74,6 +74,14 @@ export const QuoteComponent: React.FC<NodeViewProps> = (props) => {
|
|
| 74 |
const handleClick = (e: React.MouseEvent) => {
|
| 75 |
if (e.detail === 3 && props.editor.isEditable) {
|
| 76 |
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
const event = new CustomEvent('block-triple-click', {
|
| 78 |
detail: { type: 'quote', pos: props.getPos() },
|
| 79 |
bubbles: true
|
|
@@ -91,8 +99,18 @@ export const QuoteComponent: React.FC<NodeViewProps> = (props) => {
|
|
| 91 |
className="group my-4 rounded-sm transition-all [&_p]:m-0"
|
| 92 |
onClick={handleClick}
|
| 93 |
>
|
| 94 |
-
{(attrs.showCopyButton || attrs.showDownloadButton) && (
|
| 95 |
<div className="absolute top-2 right-2 z-10 flex gap-2">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
{attrs.showCopyButton && (
|
| 97 |
<button
|
| 98 |
onClick={handleCopy}
|
|
|
|
| 1 |
import React, { useState, useRef, useEffect } from 'react';
|
| 2 |
import { NodeViewWrapper, NodeViewContent, NodeViewProps } from '@tiptap/react';
|
| 3 |
+
import { Copy, Check, Download, ChevronDown, ChevronUp, Settings } from 'lucide-react';
|
| 4 |
import { DownloadButton } from './DownloadButton';
|
| 5 |
|
| 6 |
export const QuoteComponent: React.FC<NodeViewProps> = (props) => {
|
|
|
|
| 74 |
const handleClick = (e: React.MouseEvent) => {
|
| 75 |
if (e.detail === 3 && props.editor.isEditable) {
|
| 76 |
e.preventDefault();
|
| 77 |
+
handleOpenSettings(e);
|
| 78 |
+
}
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
const handleOpenSettings = (e: React.MouseEvent) => {
|
| 82 |
+
e.preventDefault();
|
| 83 |
+
e.stopPropagation();
|
| 84 |
+
if (props.editor.isEditable) {
|
| 85 |
const event = new CustomEvent('block-triple-click', {
|
| 86 |
detail: { type: 'quote', pos: props.getPos() },
|
| 87 |
bubbles: true
|
|
|
|
| 99 |
className="group my-4 rounded-sm transition-all [&_p]:m-0"
|
| 100 |
onClick={handleClick}
|
| 101 |
>
|
| 102 |
+
{(attrs.showCopyButton || attrs.showDownloadButton || isEditing) && (
|
| 103 |
<div className="absolute top-2 right-2 z-10 flex gap-2">
|
| 104 |
+
{isEditing && (
|
| 105 |
+
<button
|
| 106 |
+
onClick={(e) => handleOpenSettings(e)}
|
| 107 |
+
contentEditable={false}
|
| 108 |
+
className="p-1 bg-zinc-800/50 rounded text-zinc-300 hover:text-white transition-all backdrop-blur-sm"
|
| 109 |
+
title="Configurar Estilo"
|
| 110 |
+
>
|
| 111 |
+
<Settings size={14} />
|
| 112 |
+
</button>
|
| 113 |
+
)}
|
| 114 |
{attrs.showCopyButton && (
|
| 115 |
<button
|
| 116 |
onClick={handleCopy}
|
components/TipTapEditor.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import { CustomImageExtension } from './extensions/CustomImageExtension';
|
|
| 11 |
import { UniversalVideoExtension } from './extensions/UniversalVideoExtension';
|
| 12 |
import { CustomCodeBlock } from './extensions/CustomCodeBlock';
|
| 13 |
import { CustomButton } from './extensions/CustomButton';
|
|
|
|
| 14 |
import { EditorToolbar } from './EditorToolbar';
|
| 15 |
import { StyleSettingsPanel } from './StyleSettingsPanel';
|
| 16 |
import { EditorSelectionWrapper } from './EditorSelectionWrapper';
|
|
@@ -28,6 +29,7 @@ interface TipTapEditorProps {
|
|
| 28 |
className?: string;
|
| 29 |
extensions?: Extension[];
|
| 30 |
dense?: boolean;
|
|
|
|
| 31 |
cardStyle?: 'bordered' | 'transparent' | 'filled';
|
| 32 |
onCardStyleChange?: (style: 'bordered' | 'transparent' | 'filled') => void;
|
| 33 |
}
|
|
@@ -44,6 +46,7 @@ export const TipTapEditor: React.FC<TipTapEditorProps> = ({
|
|
| 44 |
className = '',
|
| 45 |
extensions = [],
|
| 46 |
dense = false,
|
|
|
|
| 47 |
cardStyle,
|
| 48 |
onCardStyleChange
|
| 49 |
}) => {
|
|
@@ -124,6 +127,7 @@ export const TipTapEditor: React.FC<TipTapEditorProps> = ({
|
|
| 124 |
codeBlock: false, // Disable default codeBlock to use custom configuration
|
| 125 |
horizontalRule: false, // Disable default horizontalRule to use custom configuration
|
| 126 |
blockquote: false, // Disable default blockquote to use custom configuration
|
|
|
|
| 127 |
}),
|
| 128 |
Heading.configure({
|
| 129 |
levels: [1, 2, 3],
|
|
@@ -180,6 +184,7 @@ export const TipTapEditor: React.FC<TipTapEditorProps> = ({
|
|
| 180 |
},
|
| 181 |
}),
|
| 182 |
ArrowDownHandler,
|
|
|
|
| 183 |
...extensions
|
| 184 |
],
|
| 185 |
content: (typeof content === 'string' && !content.includes('<') && content.includes('\n')) ? content.replace(/\n/g, '<br>') : content,
|
|
@@ -283,6 +288,7 @@ export const TipTapEditor: React.FC<TipTapEditorProps> = ({
|
|
| 283 |
// 2. Open settings.
|
| 284 |
// 3. In the render, if editingBlockIndex is set, pass the instance config.
|
| 285 |
setIsSettingsOpen(true);
|
|
|
|
| 286 |
} else if (type === 'code') {
|
| 287 |
setEditingBlockIndex(pos);
|
| 288 |
setIsSettingsOpen(true);
|
|
@@ -389,6 +395,7 @@ export const TipTapEditor: React.FC<TipTapEditorProps> = ({
|
|
| 389 |
<div className={`transition-opacity duration-200 ${isEditable && toolbarVisible ? 'opacity-100 pointer-events-auto' : 'opacity-0 pointer-events-none'}`}>
|
| 390 |
<EditorToolbar
|
| 391 |
editor={editor}
|
|
|
|
| 392 |
defaultQuoteStyles={styleConfig.quote}
|
| 393 |
codeStyleConfig={styleConfig.code}
|
| 394 |
linkStyleConfig={styleConfig.link}
|
|
|
|
| 11 |
import { UniversalVideoExtension } from './extensions/UniversalVideoExtension';
|
| 12 |
import { CustomCodeBlock } from './extensions/CustomCodeBlock';
|
| 13 |
import { CustomButton } from './extensions/CustomButton';
|
| 14 |
+
import { WordBehaviorExtension } from './extensions/WordBehaviorExtension';
|
| 15 |
import { EditorToolbar } from './EditorToolbar';
|
| 16 |
import { StyleSettingsPanel } from './StyleSettingsPanel';
|
| 17 |
import { EditorSelectionWrapper } from './EditorSelectionWrapper';
|
|
|
|
| 29 |
className?: string;
|
| 30 |
extensions?: Extension[];
|
| 31 |
dense?: boolean;
|
| 32 |
+
minimalMode?: boolean;
|
| 33 |
cardStyle?: 'bordered' | 'transparent' | 'filled';
|
| 34 |
onCardStyleChange?: (style: 'bordered' | 'transparent' | 'filled') => void;
|
| 35 |
}
|
|
|
|
| 46 |
className = '',
|
| 47 |
extensions = [],
|
| 48 |
dense = false,
|
| 49 |
+
minimalMode = false,
|
| 50 |
cardStyle,
|
| 51 |
onCardStyleChange
|
| 52 |
}) => {
|
|
|
|
| 127 |
codeBlock: false, // Disable default codeBlock to use custom configuration
|
| 128 |
horizontalRule: false, // Disable default horizontalRule to use custom configuration
|
| 129 |
blockquote: false, // Disable default blockquote to use custom configuration
|
| 130 |
+
strike: false, // Disable strike as it causes unwanted strikethrough on pasted syntax highlighter code
|
| 131 |
}),
|
| 132 |
Heading.configure({
|
| 133 |
levels: [1, 2, 3],
|
|
|
|
| 184 |
},
|
| 185 |
}),
|
| 186 |
ArrowDownHandler,
|
| 187 |
+
WordBehaviorExtension,
|
| 188 |
...extensions
|
| 189 |
],
|
| 190 |
content: (typeof content === 'string' && !content.includes('<') && content.includes('\n')) ? content.replace(/\n/g, '<br>') : content,
|
|
|
|
| 288 |
// 2. Open settings.
|
| 289 |
// 3. In the render, if editingBlockIndex is set, pass the instance config.
|
| 290 |
setIsSettingsOpen(true);
|
| 291 |
+
setActiveTab('quote');
|
| 292 |
} else if (type === 'code') {
|
| 293 |
setEditingBlockIndex(pos);
|
| 294 |
setIsSettingsOpen(true);
|
|
|
|
| 395 |
<div className={`transition-opacity duration-200 ${isEditable && toolbarVisible ? 'opacity-100 pointer-events-auto' : 'opacity-0 pointer-events-none'}`}>
|
| 396 |
<EditorToolbar
|
| 397 |
editor={editor}
|
| 398 |
+
minimalMode={minimalMode}
|
| 399 |
defaultQuoteStyles={styleConfig.quote}
|
| 400 |
codeStyleConfig={styleConfig.code}
|
| 401 |
linkStyleConfig={styleConfig.link}
|
components/extensions/CustomCodeBlock.ts
CHANGED
|
@@ -44,5 +44,5 @@ export const CustomCodeBlock = CodeBlock.extend({
|
|
| 44 |
};
|
| 45 |
},
|
| 46 |
content: 'text*',
|
| 47 |
-
marks: '
|
| 48 |
});
|
|
|
|
| 44 |
};
|
| 45 |
},
|
| 46 |
content: 'text*',
|
| 47 |
+
marks: '',
|
| 48 |
});
|
components/extensions/WordBehaviorExtension.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Extension } from '@tiptap/core';
|
| 2 |
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
| 3 |
+
|
| 4 |
+
export const WordBehaviorExtension = Extension.create({
|
| 5 |
+
name: 'wordBehavior',
|
| 6 |
+
|
| 7 |
+
addProseMirrorPlugins() {
|
| 8 |
+
return [
|
| 9 |
+
new Plugin({
|
| 10 |
+
key: new PluginKey('wordBehaviorPasteHandler'),
|
| 11 |
+
props: {
|
| 12 |
+
transformPastedHTML(html) {
|
| 13 |
+
// Limpia divs vacíos y saltos dobles innecesarios generados al copiar de webs
|
| 14 |
+
let cleaned = html.replace(/<div[^>]*>\s*<\/div>/gi, '');
|
| 15 |
+
// Reemplaza dobles br por un párrafo nuevo y ordenado
|
| 16 |
+
cleaned = cleaned.replace(/(<br\s*\/?>\s*){2,}/gi, '</p><p>');
|
| 17 |
+
// Elimina la proliferación de párrafos vacíos pegados accidentalmente
|
| 18 |
+
cleaned = cleaned.replace(/(<p>\s*<\/p>\s*){2,}/gi, '<p></p>');
|
| 19 |
+
// Quita los espacios inútiles al principio o fin de fragmentos
|
| 20 |
+
cleaned = cleaned.replace(/ /g, ' ');
|
| 21 |
+
|
| 22 |
+
return cleaned;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
})
|
| 26 |
+
];
|
| 27 |
+
},
|
| 28 |
+
|
| 29 |
+
addKeyboardShortcuts() {
|
| 30 |
+
return {
|
| 31 |
+
// Shift-Enter asegura un hard break sin romper el bloque estructural actual
|
| 32 |
+
'Shift-Enter': () => {
|
| 33 |
+
return this.editor.commands.setHardBreak();
|
| 34 |
+
},
|
| 35 |
+
|
| 36 |
+
// Comportamiento de sangría al estilo procesador de textos para listas
|
| 37 |
+
'Tab': () => {
|
| 38 |
+
if (this.editor.isActive('listItem')) {
|
| 39 |
+
return this.editor.commands.sinkListItem('listItem');
|
| 40 |
+
}
|
| 41 |
+
// Previene que inserte un tabulador como espacio manual si no está en un bloque soportado
|
| 42 |
+
// Si preferimos que "Tab" ponga un espacio literal en párrafos, retornamos false
|
| 43 |
+
return false;
|
| 44 |
+
},
|
| 45 |
+
|
| 46 |
+
'Shift-Tab': () => {
|
| 47 |
+
if (this.editor.isActive('listItem')) {
|
| 48 |
+
return this.editor.commands.liftListItem('listItem');
|
| 49 |
+
}
|
| 50 |
+
return false;
|
| 51 |
+
}
|
| 52 |
+
};
|
| 53 |
+
}
|
| 54 |
+
});
|