@innoviatech/lexical-text-editor 0.0.4 → 0.0.6

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.
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # @innoviatech/lexical-text-editor
2
+
3
+ A powerful, customizable rich text editor component built with Lexical, React, and Tailwind CSS. Features a modern toolbar, image support, video embedding, and comprehensive text formatting options.
4
+
5
+ ## Features
6
+
7
+ - 🎨 **Rich Text Editing** — Bold, italic, underline, strikethrough, code blocks
8
+ - 📝 **Text Formatting** — Headers, paragraphs, lists (bulleted & numbered), quotes
9
+ - 🔗 **Link Support** — Insert and edit hyperlinks
10
+ - 🖼️ **Media Embedding** — Images and YouTube videos with resizing
11
+ - 🎯 **Customizable Toolbar** — Modern, intuitive interface
12
+ - 🎨 **Color Picker** — Text and background color options
13
+ - 📱 **Responsive Design** — Works on desktop and mobile
14
+ - 🎪 **Radix UI Components** — Accessible, well-designed UI elements
15
+ - ⚡ **TypeScript Support** — Fully typed for better development experience
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @innoviatech/lexical-text-editor
23
+ ```
24
+
25
+ ### Peer Dependencies
26
+
27
+ This package requires several peer dependencies. Make sure to install them in your project:
28
+
29
+ ```bash
30
+ # UI dependencies (required for full functionality)
31
+ npm install react-icons lucide-react @radix-ui/react-slot @radix-ui/react-tooltip @radix-ui/react-popover @radix-ui/react-dialog clsx tailwind-merge class-variance-authority react-color
32
+ ```
33
+
34
+
35
+
36
+
37
+
38
+ ## Quick Start
39
+
40
+ ```tsx
41
+ import React, { useState } from 'react';
42
+ import { LexicalTextEditor } from '@innoviatech/lexical-text-editor';
43
+ import '@innoviatech/lexical-text-editor/style.css';
44
+
45
+ function App() {
46
+ const [content, setContent] = useState('');
47
+
48
+ return (
49
+ <div style={{ padding: '20px', maxWidth: '900px', margin: '0 auto' }}>
50
+ <LexicalTextEditor
51
+ name="my-editor"
52
+ value={content}
53
+ onChange={setContent}
54
+ placeholder="Start typing your content here..."
55
+ />
56
+ </div>
57
+ );
58
+ }
59
+
60
+ export default App;
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Props
66
+
67
+ | Prop | Type | Required | Default | Description |
68
+ |-------------|-------------------------------------|----------|---------------|---------------------------------------------|
69
+ | `name` | `string` | Yes | — | Unique identifier for the editor instance |
70
+ | `value` | `string` | Yes | — | Current editor content (HTML string) |
71
+ | `onChange` | `(value: string) => void` | Yes | — | Callback fired when content changes |
72
+ | `placeholder`| `string` | No | `"Some Text"` | Placeholder text when editor is empty |
73
+
74
+ ---
75
+
76
+ ## Advanced Usage
77
+
78
+ ### With Initial Content
79
+
80
+ ```tsx
81
+ import React, { useState } from 'react';
82
+ import { LexicalTextEditor } from '@innoviatech/lexical-text-editor';
83
+ import '@innoviatech/lexical-text-editor/style.css';
84
+
85
+ function App() {
86
+ const [content, setContent] = useState('<p>Welcome to the editor!</p><ul><li>Feature 1</li><li>Feature 2</li></ul>');
87
+
88
+ const handleSave = () => {
89
+ console.log('Current content:', content);
90
+ };
91
+
92
+ return (
93
+ <div>
94
+ <LexicalTextEditor
95
+ name="content-editor"
96
+ value={content}
97
+ onChange={setContent}
98
+ placeholder="Write your content..."
99
+ />
100
+ <button onClick={handleSave}>Save Content</button>
101
+ </div>
102
+ );
103
+ }
104
+
105
+ export default App;
106
+ ```
107
+
108
+
109
+ ## Toolbar Features
110
+
111
+ - Text Formatting: Bold, Italic, Underline, Strikethrough
112
+ - Headings: H1–H6
113
+ - Lists: Bulleted and Numbered
114
+ - Alignment: Left, Center, Right, Justify
115
+ - Text Case: Uppercase, Lowercase, Capitalize
116
+ - Colors: Text & background color picker
117
+ - Media: Image upload, YouTube embedding, video node
118
+ - Links: Insert and edit hyperlinks
119
+ - Code: Inline code & code blocks
120
+ - Quotes: Blockquote formatting
121
+ - Undo/Redo, Clear formatting, Remove link
122
+
123
+ ---
124
+
125
+ ## Browser Support
126
+
127
+ - Chrome 90+
128
+ - Firefox 88+
129
+ - Safari 14+
130
+ - Edge 90+
131
+
132
+ ---
133
+
134
+ ## Troubleshooting
135
+
136
+ - **Missing peer dependencies:** install required packages
137
+ - **CSS not loading:** `import '@innoviatech/lexical-text-editor/style.css'`
138
+ - **Icons not showing:** verify `react-icons` and `lucide-react`
139
+ - **Toolbar not working:** ensure Radix UI peer deps installed
140
+
141
+ ---
142
+
143
+ ## Version Compatibility
144
+
145
+ - React 18+
146
+ - Lexical 0.36.0+
147
+ - TypeScript 5.0+
148
+
149
+ ---
150
+
151
+ ## License
152
+
153
+ MIT © Innoviatech
154
+
155
+ ---
156
+
157
+ ## Support
158
+
159
+ For issues and feature requests, open an issue on GitHub.
160
+
161
+ Built with ❤️ by Innoviatech
package/package.json CHANGED
@@ -1,16 +1,22 @@
1
1
  {
2
2
  "name": "@innoviatech/lexical-text-editor",
3
- "version": "0.0.4",
4
- "description": "Reusable rich text editor component",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "license": "MIT",
9
- "publishConfig": {
10
- "access": "public"
3
+ "version": "0.0.6",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.esm.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.esm.js",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./style.css": "./dist/style.css"
11
15
  },
12
16
  "scripts": {
13
- "rollup": "rollup -c --bundleConfigAsCjs"
17
+ "build": "rollup -c",
18
+ "dev": "rollup -c --watch",
19
+ "prepublishOnly": "npm run build"
14
20
  },
15
21
  "peerDependencies": {
16
22
  "react": ">=18",
@@ -20,38 +26,24 @@
20
26
  "@lexical/rich-text": "^0.36.2",
21
27
  "@lexical/list": "^0.36.2",
22
28
  "@lexical/link": "^0.36.2",
23
- "@lexical/code": "^0.36.2",
24
- "clsx": "^2.1.1",
25
- "tailwind-merge": "^3.3.1",
26
- "class-variance-authority": "^0.7.1",
27
- "@radix-ui/react-popover": "^1.1.15",
28
- "@radix-ui/react-tooltip": "^1.2.8",
29
- "@radix-ui/react-dialog": "^1.1.15",
30
- "react-icons": "^5.5.0"
31
- },
32
- "dependencies": {
33
- "lucide-react": "^0.546.0",
34
- "react-color": "^2.19.3"
29
+ "@lexical/code": "^0.36.2"
35
30
  },
36
31
  "devDependencies": {
37
- "@rollup/plugin-commonjs": "^28.0.8",
38
- "@rollup/plugin-node-resolve": "^16.0.3",
39
- "@rollup/plugin-terser": "^0.4.4",
40
- "@rollup/plugin-typescript": "^12.1.4",
41
- "typescript": "^5.9.3",
42
- "tslib": "^2.8.1",
43
- "rollup-plugin-dts": "^6.2.3",
32
+ "@rollup/plugin-commonjs": "^28.0.0",
33
+ "@rollup/plugin-node-resolve": "^16.0.0",
34
+ "@rollup/plugin-terser": "^0.4.0",
35
+ "@rollup/plugin-typescript": "^12.0.0",
36
+ "typescript": "^5.0.0",
37
+ "tslib": "^2.6.0",
38
+ "rollup-plugin-dts": "^6.1.0",
44
39
  "rollup-plugin-peer-deps-external": "^2.2.4",
45
40
  "rollup-plugin-postcss": "^4.0.2",
46
- "@types/react": "^19.2.2",
47
- "@types/react-dom": "^19.2.2",
48
- "@types/react-color": "^3.0.13",
49
- "lexical": "^0.36.2",
50
- "@lexical/code": "^0.36.2",
51
- "@lexical/link": "^0.36.2",
52
- "@lexical/list": "^0.36.2",
53
- "@lexical/react": "^0.36.2",
54
- "@lexical/rich-text": "^0.36.2",
55
- "react": "^19.2.0"
41
+ "autoprefixer": "^10.4.0",
42
+ "postcss": "^8.4.0",
43
+ "tailwindcss": "^3.3.0",
44
+ "react": "^18.0.0",
45
+ "react-dom": "^18.0.0",
46
+ "@types/react": "^18.0.0",
47
+ "@types/react-dom": "^18.0.0"
56
48
  }
57
49
  }
@@ -0,0 +1,6 @@
1
+ export default {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ }
6
+ }
package/rollup.config.js CHANGED
@@ -1,40 +1,56 @@
1
- const resolve = require('@rollup/plugin-node-resolve').default;
2
- const typescript = require('@rollup/plugin-typescript');
3
- const commonjs = require('@rollup/plugin-commonjs');
4
- const peerDepsExternal = require('rollup-plugin-peer-deps-external');
5
- const terser = require('@rollup/plugin-terser');
6
- const dts = require('rollup-plugin-dts').default;
7
- const postcss = require('rollup-plugin-postcss');
8
- const packageJson = require('./package.json');
1
+ import resolve from '@rollup/plugin-node-resolve';
2
+ import typescript from '@rollup/plugin-typescript';
3
+ import commonjs from '@rollup/plugin-commonjs';
4
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external';
5
+ import terser from '@rollup/plugin-terser';
6
+ import dts from 'rollup-plugin-dts';
7
+ import postcss from 'rollup-plugin-postcss';
9
8
 
10
- module.exports = [
9
+ export default [
11
10
  {
12
11
  input: 'src/index.ts',
13
12
  output: [
14
- { file: packageJson.main, format: 'cjs', sourcemap: true },
15
- { file: packageJson.module, format: 'esm', sourcemap: true }
13
+ {
14
+ file: 'dist/index.js',
15
+ format: 'cjs',
16
+ sourcemap: true,
17
+ exports: 'named'
18
+ },
19
+ {
20
+ file: 'dist/index.esm.js',
21
+ format: 'esm',
22
+ sourcemap: true,
23
+ exports: 'named'
24
+ }
16
25
  ],
17
26
  plugins: [
18
27
  peerDepsExternal(),
19
- resolve(),
28
+ resolve({
29
+ browser: true,
30
+ preferBuiltins: false
31
+ }),
20
32
  commonjs(),
21
- typescript({ tsconfig: './tsconfig.json' }),
22
- postcss({ extract: true }),
33
+ postcss({
34
+ extract: 'style.css',
35
+ minimize: true,
36
+ config: {
37
+ path: './postcss.config.js'
38
+ }
39
+ }),
40
+ typescript({
41
+ tsconfig: './tsconfig.json',
42
+ declaration: true,
43
+ declarationDir: 'dist',
44
+ rootDir: 'src',
45
+ noEmitOnError: false
46
+ }),
23
47
  terser()
24
- ],
25
- external: [
26
- "react", "react-dom",
27
- "lexical", "@lexical/react", "@lexical/rich-text",
28
- "@lexical/list", "@lexical/link", "@lexical/code",
29
- "clsx", "tailwind-merge", "class-variance-authority",
30
- "@radix-ui/react-popover", "@radix-ui/react-tooltip", "@radix-ui/react-dialog",
31
- "react-icons", "react-color"
32
48
  ]
33
49
  },
34
50
  {
35
- input: 'src/index.ts',
36
- output: [{ file: packageJson.types }],
51
+ input: 'dist/index.d.ts',
52
+ output: [{ file: 'dist/index.d.ts', format: 'esm' }],
37
53
  plugins: [dts()],
38
54
  external: [/\.css$/]
39
55
  }
40
- ];
56
+ ];
@@ -1,4 +1,3 @@
1
- "use client";
2
1
 
3
2
  import { useState, useRef, useEffect } from "react";
4
3
  import { SketchPicker } from "react-color";
@@ -1,4 +1,3 @@
1
- "use client";
2
1
 
3
2
  import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "./ui/dialog";
4
3
  import { Button } from "./ui/button";
@@ -1,4 +1,3 @@
1
- import { ImageNode } from "../nodes/ImageNode";
2
1
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
2
  import { $getNodeByKey, type NodeKey } from "lexical";
4
3
  import { useRef, useState } from "react";
@@ -33,7 +32,6 @@ export const ImageComponent: React.FC<ImageComponentProps> = ({
33
32
  height: number;
34
33
  } | null>(null);
35
34
 
36
-
37
35
  const onMouseDown = (e: React.MouseEvent) => {
38
36
  e.preventDefault();
39
37
  e.stopPropagation();
@@ -61,14 +59,16 @@ export const ImageComponent: React.FC<ImageComponentProps> = ({
61
59
 
62
60
  editor.update(() => {
63
61
  const node = $getNodeByKey(nodeKey);
64
- if (node && node instanceof ImageNode) {
65
- node.updateDimensions(currentSize.width as number, currentSize.height as number);
62
+ // Use the node directly without importing ImageNode
63
+ if (node && typeof (node as any).updateDimensions === 'function') {
64
+ (node as any).updateDimensions(currentSize.width as number, currentSize.height as number);
66
65
  }
67
66
  });
68
67
 
69
68
  window.removeEventListener("mousemove", onMouseMove);
70
69
  window.removeEventListener("mouseup", onMouseUp);
71
70
  };
71
+
72
72
  return (
73
73
  <div
74
74
  ref={wrapperRef}
@@ -104,4 +104,4 @@ export const ImageComponent: React.FC<ImageComponentProps> = ({
104
104
  />
105
105
  </div>
106
106
  );
107
- };
107
+ };
@@ -18,7 +18,7 @@ import { YoutubeNode } from "../nodes/YoutubeNode"
18
18
  import { VideoNode } from "../nodes/VideoNode"
19
19
  import "../styles/lexical-editor.css"
20
20
 
21
- interface LexiTexProps {
21
+ export interface LexiTexProps {
22
22
  value: string
23
23
  onChange: (value: string) => void
24
24
  placeholder?: string
@@ -47,12 +47,11 @@ const theme: EditorThemeClasses = {
47
47
  quote: "border-l-4 border-gray-400 pl-4 italic text-gray-800 bg-gray-50 py-2 rounded-r",
48
48
  link: "text-blue-600 underline hover:text-blue-800",
49
49
  }
50
+ // ... your imports
50
51
 
51
52
  export const LexicalTextEditor: React.FC<LexiTexProps> = React.memo(
52
53
  function LexicalTextEditor({ name, value, onChange, placeholder }) {
53
54
 
54
- // console.log({ value });
55
-
56
55
  const initialConfig = useMemo(
57
56
  () => ({
58
57
  namespace: name,
@@ -72,13 +71,12 @@ export const LexicalTextEditor: React.FC<LexiTexProps> = React.memo(
72
71
  YoutubeNode,
73
72
  VideoNode
74
73
  ],
75
- }) as any, // <- cast the whole config
74
+ }) as any,
76
75
  [name]
77
76
  );
78
77
 
79
-
80
78
  return (
81
- <div className="border-[1px] rounded-lg w-full max-w-[900px] pb-2 scrollbar-thin">
79
+ <div className="lexical-text-editor border-[1px] rounded-lg w-full max-w-[900px] pb-2 scrollbar-thin">
82
80
  <LexicalComposer initialConfig={initialConfig}>
83
81
  <div className="px-2">
84
82
  <ToolbarPlugin value={value} />
@@ -104,15 +102,4 @@ export const LexicalTextEditor: React.FC<LexiTexProps> = React.memo(
104
102
  </div>
105
103
  )
106
104
  }
107
- )
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
105
+ )
@@ -1,6 +1,6 @@
1
1
  import * as React from "react"
2
2
  import { Slot } from "@radix-ui/react-slot"
3
- import { cva, type VariantProps } from "class-variance-authority"
3
+ import { cva } from "class-variance-authority"
4
4
 
5
5
  import { cn } from "../../lib/utils"
6
6
 
@@ -12,14 +12,10 @@ const buttonVariants = cva(
12
12
  default: "bg-primary text-primary-foreground hover:bg-primary/90",
13
13
  toolbar: "bg-transparent hover:bg-slate-100/80 text-gray-600",
14
14
  toolbarActive: "bg-slate-100 text-gray-900 ",
15
- destructive:
16
- "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
17
- outline:
18
- "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
19
- secondary:
20
- "bg-secondary text-secondary-foreground hover:bg-secondary/80",
21
- ghost:
22
- "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
15
+ destructive: "bg-destructive text-white hover:bg-destructive/90",
16
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",
17
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
18
+ ghost: "hover:bg-accent hover:text-accent-foreground",
23
19
  link: "text-primary underline-offset-4 hover:underline",
24
20
  },
25
21
  size: {
@@ -36,25 +32,27 @@ const buttonVariants = cva(
36
32
  }
37
33
  )
38
34
 
39
- function Button({
40
- className,
41
- variant,
42
- size,
43
- asChild = false,
44
- ...props
45
- }: React.ComponentProps<"button"> &
46
- VariantProps<typeof buttonVariants> & {
47
- asChild?: boolean
48
- }) {
49
- const Comp = asChild ? Slot : "button"
50
-
51
- return (
52
- <Comp
53
- data-slot="button"
54
- className={cn(buttonVariants({ variant, size, className }))}
55
- {...props}
56
- />
57
- )
35
+ // Simple props interface without complex types
36
+ interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
37
+ variant?: "default" | "toolbar" | "toolbarActive" | "destructive" | "outline" | "secondary" | "ghost" | "link"
38
+ size?: "default" | "sm" | "lg" | "icon"
39
+ asChild?: boolean
58
40
  }
59
41
 
60
- export { Button, buttonVariants }
42
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
43
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
44
+ const Comp = asChild ? Slot : "button"
45
+
46
+ return (
47
+ <Comp
48
+ data-slot="button"
49
+ className={cn(buttonVariants({ variant, size, className }))}
50
+ ref={ref}
51
+ {...props}
52
+ />
53
+ )
54
+ }
55
+ )
56
+ Button.displayName = "Button"
57
+
58
+ export { Button, buttonVariants }
@@ -28,7 +28,7 @@ function PopoverContent({
28
28
  align={align}
29
29
  sideOffset={sideOffset}
30
30
  className={cn(
31
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
31
+ "bg-white text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
32
32
  className
33
33
  )}
34
34
  {...props}
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
+ // Export main component
2
+ export { LexicalTextEditor } from './components/LexicalTextEditor';
3
+ export type { LexiTexProps as LexicalTextEditorProps } from './components/LexicalTextEditor';
1
4
 
2
- import { LexicalTextEditor } from './components/LexicalTextEditor'
3
-
4
- export default LexicalTextEditor;
5
+ // Export styles
6
+ import './styles/lexical-editor.css';
package/src/lib/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { clsx, type ClassValue } from "clsx"
2
- import { twMerge } from "tailwind-merge"
1
+ import { clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
3
 
4
- export function cn(...inputs: ClassValue[]) {
5
- return twMerge(clsx(inputs))
6
- }
4
+ export function cn(...inputs: any[]) {
5
+ return twMerge(clsx(inputs));
6
+ }