@qwanyx/ai-editor 1.1.0 → 1.2.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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichTextViewer.d.ts","sourceRoot":"","sources":["../../src/components/RichTextViewer.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AA4ID,wBAAgB,cAAc,CAAC,EAC7B,OAAY,EACZ,SAAc,EACf,EAAE,mBAAmB,kDA4BrB"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
5
|
+
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
6
|
+
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
7
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
8
|
+
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
9
|
+
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
|
10
|
+
import { ListNode, ListItemNode } from '@lexical/list';
|
|
11
|
+
import { LinkNode } from '@lexical/link';
|
|
12
|
+
import { ImageNode } from '../nodes/ImageNode';
|
|
13
|
+
import { ImageLinkNode } from '../nodes/ImageLinkNode';
|
|
14
|
+
import { SimpleLinkNode } from '../nodes/LinkNode';
|
|
15
|
+
import { ImageLinkPlugin } from '../plugins/ImageLinkPlugin';
|
|
16
|
+
import { SimpleLinkPlugin } from '../plugins/LinkPlugin';
|
|
17
|
+
import { ListPlugin } from '@lexical/react/LexicalListPlugin';
|
|
18
|
+
import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
|
|
19
|
+
// Theme for Lexical viewer (same as editor)
|
|
20
|
+
const viewerTheme = {
|
|
21
|
+
paragraph: 'editor-paragraph',
|
|
22
|
+
heading: {
|
|
23
|
+
h1: 'editor-heading-h1',
|
|
24
|
+
h2: 'editor-heading-h2',
|
|
25
|
+
h3: 'editor-heading-h3',
|
|
26
|
+
},
|
|
27
|
+
text: {
|
|
28
|
+
bold: 'editor-text-bold',
|
|
29
|
+
italic: 'editor-text-italic',
|
|
30
|
+
underline: 'editor-text-underline',
|
|
31
|
+
strikethrough: 'editor-text-strikethrough',
|
|
32
|
+
},
|
|
33
|
+
list: {
|
|
34
|
+
ul: 'editor-list-ul',
|
|
35
|
+
ol: 'editor-list-ol',
|
|
36
|
+
listitem: 'editor-listitem',
|
|
37
|
+
nested: {
|
|
38
|
+
listitem: 'editor-nested-listitem',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
quote: 'editor-quote',
|
|
42
|
+
link: 'editor-link',
|
|
43
|
+
};
|
|
44
|
+
// CSS styles for the viewer (same as editor)
|
|
45
|
+
const viewerStyles = `
|
|
46
|
+
.editor-paragraph {
|
|
47
|
+
margin-bottom: 8px;
|
|
48
|
+
}
|
|
49
|
+
.editor-heading-h1 {
|
|
50
|
+
font-size: 1.875rem;
|
|
51
|
+
font-weight: bold;
|
|
52
|
+
margin-bottom: 16px;
|
|
53
|
+
margin-top: 24px;
|
|
54
|
+
}
|
|
55
|
+
.editor-heading-h2 {
|
|
56
|
+
font-size: 1.5rem;
|
|
57
|
+
font-weight: bold;
|
|
58
|
+
margin-bottom: 12px;
|
|
59
|
+
margin-top: 20px;
|
|
60
|
+
}
|
|
61
|
+
.editor-heading-h3 {
|
|
62
|
+
font-size: 1.25rem;
|
|
63
|
+
font-weight: 600;
|
|
64
|
+
margin-bottom: 8px;
|
|
65
|
+
margin-top: 16px;
|
|
66
|
+
}
|
|
67
|
+
.editor-text-bold {
|
|
68
|
+
font-weight: bold;
|
|
69
|
+
}
|
|
70
|
+
.editor-text-italic {
|
|
71
|
+
font-style: italic;
|
|
72
|
+
}
|
|
73
|
+
.editor-text-underline {
|
|
74
|
+
text-decoration: underline;
|
|
75
|
+
}
|
|
76
|
+
.editor-text-strikethrough {
|
|
77
|
+
text-decoration: line-through;
|
|
78
|
+
}
|
|
79
|
+
.editor-list-ul {
|
|
80
|
+
list-style-type: disc;
|
|
81
|
+
margin-left: 24px;
|
|
82
|
+
margin-bottom: 8px;
|
|
83
|
+
padding-left: 0;
|
|
84
|
+
}
|
|
85
|
+
.editor-list-ol {
|
|
86
|
+
list-style-type: decimal;
|
|
87
|
+
margin-left: 24px;
|
|
88
|
+
margin-bottom: 8px;
|
|
89
|
+
padding-left: 0;
|
|
90
|
+
}
|
|
91
|
+
.editor-listitem {
|
|
92
|
+
margin-bottom: 4px;
|
|
93
|
+
}
|
|
94
|
+
.editor-nested-listitem {
|
|
95
|
+
list-style-type: none;
|
|
96
|
+
}
|
|
97
|
+
.editor-quote {
|
|
98
|
+
border-left: 4px solid #d1d5db;
|
|
99
|
+
padding-left: 16px;
|
|
100
|
+
font-style: italic;
|
|
101
|
+
color: #6b7280;
|
|
102
|
+
margin: 16px 0;
|
|
103
|
+
}
|
|
104
|
+
.editor-link {
|
|
105
|
+
color: #2563eb;
|
|
106
|
+
text-decoration: underline;
|
|
107
|
+
}
|
|
108
|
+
.editor-link:hover {
|
|
109
|
+
color: #1e40af;
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
// Viewer config
|
|
113
|
+
function getViewerConfig() {
|
|
114
|
+
return {
|
|
115
|
+
namespace: 'RichTextViewer',
|
|
116
|
+
theme: viewerTheme,
|
|
117
|
+
editable: false,
|
|
118
|
+
onError: (error) => {
|
|
119
|
+
console.error('Lexical viewer error:', error);
|
|
120
|
+
},
|
|
121
|
+
nodes: [
|
|
122
|
+
HeadingNode,
|
|
123
|
+
QuoteNode,
|
|
124
|
+
ListNode,
|
|
125
|
+
ListItemNode,
|
|
126
|
+
LinkNode,
|
|
127
|
+
ImageNode,
|
|
128
|
+
ImageLinkNode,
|
|
129
|
+
SimpleLinkNode,
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Plugin to load content
|
|
134
|
+
function ContentLoaderPlugin({ content }) {
|
|
135
|
+
const [editor] = useLexicalComposerContext();
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (content) {
|
|
138
|
+
try {
|
|
139
|
+
const parsed = JSON.parse(content);
|
|
140
|
+
if (parsed.root) {
|
|
141
|
+
const editorState = editor.parseEditorState(parsed);
|
|
142
|
+
editor.setEditorState(editorState);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// Not valid JSON, ignore
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}, [editor, content]);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
export function RichTextViewer({ content = '', className = '' }) {
|
|
153
|
+
// Don't render anything if no content
|
|
154
|
+
if (!content) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
return (_jsxs("div", { className: className, children: [_jsx("style", { dangerouslySetInnerHTML: { __html: viewerStyles } }), _jsxs(LexicalComposer, { initialConfig: getViewerConfig(), children: [_jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: "outline-none text-gray-900", style: { cursor: 'default' } }), placeholder: null, ErrorBoundary: LexicalErrorBoundary }), _jsx(ListPlugin, {}), _jsx(LinkPlugin, {}), _jsx(ContentLoaderPlugin, { content: content }), _jsx(ImageLinkPlugin, {}), _jsx(SimpleLinkPlugin, {})] })] }));
|
|
158
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { RichTextEditor } from './components/RichTextEditor';
|
|
2
2
|
export type { RichTextEditorProps } from './components/RichTextEditor';
|
|
3
|
+
export { RichTextViewer } from './components/RichTextViewer';
|
|
4
|
+
export type { RichTextViewerProps } from './components/RichTextViewer';
|
|
3
5
|
export { EditorToolbar } from './components/EditorToolbar';
|
|
4
6
|
export type { EditorToolbarProps } from './components/EditorToolbar';
|
|
5
7
|
export { ImageNode, $createImageNode, $isImageNode } from './nodes/ImageNode';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,YAAY,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAGtE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAGpE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC7E,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAErE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AACxH,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AACvH,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGzD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAGvD,OAAO,EAAE,cAAc,IAAI,QAAQ,EAAE,MAAM,6BAA6B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,YAAY,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAGtE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,YAAY,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAGtE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAGpE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC7E,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAErE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AACxH,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AACvH,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGzD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAGvD,OAAO,EAAE,cAAc,IAAI,QAAQ,EAAE,MAAM,6BAA6B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Main WYSIWYG editor component
|
|
2
2
|
export { RichTextEditor } from './components/RichTextEditor';
|
|
3
|
+
// Read-only viewer component
|
|
4
|
+
export { RichTextViewer } from './components/RichTextViewer';
|
|
3
5
|
// Toolbar component (for custom implementations)
|
|
4
6
|
export { EditorToolbar } from './components/EditorToolbar';
|
|
5
7
|
// Custom nodes
|