@innoviatech/lexical-text-editor 1.0.6 → 2.0.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.
- package/README.md +105 -35
- package/dist/components/ContentPreview.d.ts +1 -1
- package/dist/components/HeadingSelectionList.d.ts +1 -1
- package/dist/components/LexicalTextEditor.d.ts +1 -1
- package/dist/components/common/Dialog.d.ts +9 -0
- package/dist/components/common/Popover.d.ts +21 -0
- package/dist/components/common/Tooltip.d.ts +10 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical-editor.css +1 -0
- package/dist/nodes/ExtendedTextNode.d.ts +11 -0
- package/dist/nodes/ImageNode.d.ts +1 -1
- package/dist/plugins/YoutubePlugin.d.ts +1 -0
- package/package.json +20 -16
- package/rollup.config.js +3 -4
- package/src/components/AlignmentSelectionList.tsx +41 -24
- package/src/components/ColorPicker.tsx +7 -21
- package/src/components/ContentPreview.tsx +27 -20
- package/src/components/DropdownList.tsx +39 -24
- package/src/components/HeadingSelectionList.tsx +48 -32
- package/src/components/ImageComponent.tsx +52 -19
- package/src/components/InsertDropdownList.tsx +1 -1
- package/src/components/LexicalTextEditor.tsx +33 -28
- package/src/components/LinkModal.tsx +42 -45
- package/src/components/common/Dialog.tsx +47 -0
- package/src/components/common/Popover.tsx +87 -0
- package/src/components/common/Tooltip.tsx +43 -0
- package/src/components/ui/command.tsx +0 -1
- package/src/nodes/ExtendedTextNode.tsx +174 -0
- package/src/nodes/ImageNode.tsx +48 -9
- package/src/plugins/ColorPlugin.tsx +19 -14
- package/src/plugins/ImagePlugin.tsx +79 -84
- package/src/plugins/ListPlugin.tsx +20 -38
- package/src/plugins/ToolbarPlugin.tsx +76 -78
- package/src/plugins/VideoPlugin.tsx +46 -55
- package/src/plugins/YoutubePlugin.tsx +83 -0
- package/src/styles/lexical-editor.css +962 -3
- package/dist/style.css +0 -3
- package/postcss.config.js +0 -6
- package/src/assets/react.svg +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*{box-sizing:border-box;margin:0;padding:0}.lexical-text-editor *{box-sizing:border-box;font-family:inherit}.lexical-text-editor button{background:transparent;border:1px solid transparent;cursor:pointer}.lexical-text-editor a{color:#646cff;font-weight:500;text-decoration:inherit}.lexical-text-editor a:hover{color:#535bf2}.lexical-text-editor{background-color:#fff;border:1px solid #e5e7eb;border-radius:.5rem;color:#000;font-size:16px!important;padding-bottom:.5rem;scrollbar-color:#9ca3af transparent;scrollbar-width:thin}.lexical-text-editor input{background-color:#fff;color:#000;outline:none}.link-editor-buttons input{stroke:#000;background-color:#220909;color:#000;outline:none}.lexical-text-editor input:focus{border:1px solid #676666}.lexical-toolbar-wrapper{align-items:center;display:flex;flex-wrap:wrap;gap:6px;justify-content:center;row-gap:12px}.lexical-toolbar-wrapper.useScroll{flex-wrap:nowrap}.lexical-text-editor::-webkit-scrollbar{width:6px}.lexical-text-editor::-webkit-scrollbar-track{background:transparent}.lexical-text-editor::-webkit-scrollbar-thumb{background-color:#9ca3af;border-radius:3px}.lexical-text-editor::-webkit-scrollbar-thumb:hover{background-color:#6b7280}.lexical-text-editor [contenteditable=true]{outline:none}.lexical-text-editor h1{font-size:32px;font-weight:700;margin:8px 0}.lexical-text-editor h2{font-size:28.8px;font-weight:700;margin:8px 0}.lexical-text-editor h3{font-size:25.6px;font-weight:700;margin:3.2px 0}.lexical-text-editor h4{font-size:22.4px;font-weight:700;margin:3.2px 0}.lexical-text-editor h5{font-size:19.2px;font-weight:700;margin:3.2px 0}.lexical-text-editor h6{font-size:16px;font-weight:700;margin:3.2px 0}.scrollbar-thin{scrollbar-color:#a5acb6 transparent;scrollbar-width:thin}.scrollbar-thin::-webkit-scrollbar{height:4px;width:4px}.scrollbar-thin::-webkit-scrollbar-track{background:transparent}.scrollbar-thin::-webkit-scrollbar-thumb{background-color:#a5acb6;border-radius:9999px}.lexical-editor-container{box-sizing:border-box;position:relative}.lexical-toolbar-container{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;padding-left:.5rem;padding-right:.5rem}.lexical-editor-inner{height:100%;position:relative}.lexical-content-editable{background-color:#fff;box-sizing:border-box;color:#000;font-size:14px;height:100%;outline:0;overflow:auto;padding:8px;scrollbar-color:#9ca3af transparent;scrollbar-width:thin;text-align:start;width:100%}.lexical-placeholder{color:#999;font-size:14px;left:10px;pointer-events:none;position:absolute;top:8px;user-select:none}.lexical-content-editable::-webkit-scrollbar{height:8px;width:8px}.lexical-content-editable::-webkit-scrollbar-track{background:#f1f1f1;border-radius:4px}.lexical-content-editable::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:4px}.lexical-content-editable::-webkit-scrollbar-thumb:hover{background:#a8a8a8}.lexical-bold{font-weight:700}.lexical-underline{text-decoration:underline}.lexical-italic{font-style:italic}.lexical-strikethrough{text-decoration:line-through}.lexical-underline-strikethrough{text-decoration:underline line-through}.lexical-uppercase{text-transform:uppercase}.lexical-lowercase{text-transform:lowercase}.lexical-capitalize{text-transform:capitalize}.lexical-code{background-color:#f3f4f6;border:1px solid #d1d5db;border-radius:.25rem;color:#000;font-family:monospace;font-size:.875rem;padding:0 .25rem}.lexical-paragraph{margin-bottom:.5rem}.lexical-list-ul{list-style-type:disc}.lexical-list-ol,.lexical-list-ul{list-style-position:inside;padding-left:1.5rem}.lexical-list-ol{list-style-type:decimal}.lexical-listitem{margin-bottom:.25rem}.lexical-quote{background-color:#f9fafb;border-bottom-right-radius:.25rem;border-left:4px solid #9ca3af;border-top-right-radius:.25rem;color:#374151;font-style:italic;padding-bottom:.5rem;padding-left:1rem;padding-top:.5rem}.lexical-link{color:#2563eb;text-decoration:underline}.lexical-link:hover{color:#1e40af}.lexical-text-editor .lexical-btn{align-items:center;background:#fff;border:none;border-radius:6px;color:#4b5563;cursor:pointer;display:inline-flex;font-size:14px;font-weight:500;gap:8px;height:32px;justify-content:flex-start;outline:none;padding:8px 12px;transition:all .15s ease;user-select:none;white-space:nowrap;width:100%}.lexical-text-editor .lexical-btn svg{flex-shrink:0;height:16px;pointer-events:none;width:16px}.lexical-text-editor .lexical-btn svg[class*=size-]{height:auto;width:auto}.lexical-text-editor .lexical-btn .label{margin-left:8px}.lexical-text-editor .lexical-btn.toolbar{background:#fff;color:#4b5563}.lexical-text-editor .lexical-btn.toolbar:hover{background:rgba(241,245,249,.8)}.lexical-text-editor .lexical-btn.toolbar-active{background:#f1f5f9;color:#111827}.lexical-text-editor .lexical-btn:disabled{opacity:.5;pointer-events:none}.lexical-text-editor .size-8{height:32px!important;width:32px!important}.lexical-text-editor .toolbar{align-items:center;background-color:#fff;border-radius:8px;color:#374151;cursor:pointer;display:inline-flex;justify-content:flex-start;transition:background .15s ease,border-color .15s ease}.lexical-text-editor .toolbar.icon{align-items:center;display:inline-flex;justify-content:center!important}.lexical-text-editor .toolbar:hover:not(:disabled){background-color:#f3f4f6}.lexical-text-editor .toolbarActive{align-items:center;background-color:#eef2ff;border-radius:.5rem;cursor:pointer;display:inline-flex;justify-content:center;padding:0}.lexical-text-editor button:disabled{background-color:#f9fafb;cursor:not-allowed;opacity:.5}.lexical-text-editor .popover-root{display:inline-block;position:relative}.lexical-text-editor .popover-trigger{display:inline-block}.lexical-text-editor .popover-content{animation:popoverFadeIn .15s ease;background:#fff;border-radius:6px;box-shadow:0 2px 6px rgba(0,0,0,.12),0 0 0 1px rgba(0,0,0,.04);padding:8px;position:absolute;top:calc(100% + 4px);z-index:9999}.lexical-text-editor .popover-content.align-start{left:0}.lexical-text-editor .popover-content.align-center{left:50%;transform:translateX(-50%)}.lexical-text-editor .popover-content.align-end{right:0}@keyframes popoverFadeIn{0%{opacity:0;transform:translateY(-3px)}to{opacity:1;transform:translateY(0)}}.lexical-text-editor .heading-select{display:inline-block;position:relative}.lexical-text-editor .heading-trigger{background-color:#fff;border:1px solid #e5e7eb;height:32px;justify-content:space-between;padding:8px}.lexical-text-editor .heading-trigger .chevron{transition:transform .15s ease}.lexical-text-editor .heading-trigger .chevron.rotated{transform:rotate(180deg)}.lexical-text-editor .heading-dropdown{animation:dropdownFadeIn .15s ease;background:#fff;border-radius:6px;box-shadow:0 2px 6px rgba(0,0,0,.12),0 0 0 1px rgba(0,0,0,.04);display:flex;flex-direction:column;gap:4px;left:0;padding:8px;position:absolute;top:calc(100% + 4px);width:max-content;z-index:9999}@keyframes dropdownFadeIn{0%{opacity:0;transform:translateY(-3px)}to{opacity:1;transform:translateY(0)}}.color-picker-wrapper{display:inline-block;position:relative}.toolbar:hover:not(:disabled){background-color:#f3f4f6}.lexical-color-popover{border-radius:.5rem;margin-top:10px;opacity:0;pointer-events:none;transform:scale(.95) translateY(-4px);transform-origin:top left;transition:opacity .15s ease,transform .15s ease;z-index:99}.lexical-color-popover.open{opacity:1;pointer-events:auto;transform:scale(1) translateY(0)}.lexical-text-editor-dialog{.lte-icon-btn{align-items:center;background:none;border:none;border-radius:4px;cursor:pointer;display:flex;padding:6px}.lte-icon-btn:hover{background:#e5e5e5}.lte-outline-btn{background:#f8f8f8;border:1px solid #ccc;border-radius:4px;color:#000;cursor:pointer;font-size:14px;margin:0 auto;padding:8px 12px;width:fit-content}.lte-outline-btn:hover{background:#eee}.lte-primary-btn{background-color:#2563eb!important;border:none;border-radius:4px;color:#fff;cursor:pointer;padding:8px 14px}.lte-primary-btn:hover{background:#1d4ed8}.lte-primary-btn:disabled{cursor:not-allowed;opacity:.5}.lte-input{background-color:#fff;border:1px solid #d0d0d0;border-radius:4px;padding:8px 10px;width:100%}.lte-divider{align-items:center;color:#777;display:flex;font-size:13px;margin:12px 0}.lte-divider:after,.lte-divider:before{background:#ccc;content:"";flex:1;height:1px}.lte-divider span{padding:0 8px}.lte-file-name{color:#666;font-size:13px}.lte-dialog-overlay{align-items:center;background:rgba(0,0,0,.5);display:flex;inset:0;justify-content:center;position:fixed;z-index:50}.lte-dialog{background:#fff;border-radius:8px;margin:10px;max-width:420px;padding:20px;position:relative;width:100%}.lte-dialog.preview{max-width:1024px;width:100%}.lte-dialog-header{color:#333;font-size:18px;font-weight:600;margin-bottom:10px}.lte-dialog-body{display:flex;flex-direction:column;gap:12px;padding:10px 0}.lte-dialog-footer{display:flex;justify-content:flex-end;margin-top:12px}.lte-dialog-close{background:none;border:none;color:#000;cursor:pointer;font-size:26px;opacity:.7;outline:none;padding:0;position:absolute;right:18px;top:10px}.lte-dialog-close:hover{opacity:1}.lte-hidden{display:none}}.lexical-text-editor .lte-toolbar-btn{align-items:center;background:#fff;border:1px solid #e5e7eb;border-radius:6px;cursor:pointer;display:flex;gap:4px;padding:6px 10px;transition:.15s ease;user-select:none}.lexical-text-editor .lte-toolbar-btn:hover{background:#f3f4f6}.lexical-text-editor .lte-toolbar-btn-active{background:#e0e7ff;border-color:#6366f1}.lexical-text-editor .lte-preview-container{background:#fff;border:1px solid #e5e7eb;border-radius:8px;max-height:80vh;min-height:400px;overflow-y:auto;padding:2vw;width:100%}.lexical-text-editor .lte-preview-title{border-bottom:2px solid #e5e7eb;font-size:15px;font-weight:600;margin-bottom:14px;padding-bottom:6px;text-align:start}.lexical-text-editor-html-preview{line-height:1.6;max-width:none;text-align:start}.lexical-text-editor-link.link-editor-container{align-items:center;background:#fff;border:1px solid #e5e7eb;border-radius:12px;bottom:-50px;box-shadow:0 4px 12px rgba(0,0,0,.12);display:flex;gap:8px;padding:6px 10px;position:absolute;right:20px;z-index:99}@media (min-width:640px){.lexical-text-editor-link.link-editor-container{bottom:-60px;padding:8px 14px}}.lexical-text-editor-link .link-editor-input-wrapper{flex:1;min-width:200px}.lexical-text-editor-link .link-editor-input{background-color:#fff;border:1px solid #d1d5db;border-radius:6px;font-size:14px;height:32px;outline:none;padding:4px 8px;width:100%}.lexical-text-editor-link .link-editor-input:focus{border-color:#2563eb}.lexical-text-editor-link .link-editor-url{color:#2563eb;display:block;font-size:14px;max-width:100%;overflow:hidden;text-align:start;text-decoration:underline;text-overflow:ellipsis;white-space:nowrap}.lexical-text-editor-link .link-editor-buttons{display:flex;gap:4px}.lexical-text-editor-link .link-editor-btn{align-items:center;background:transparent;border:none;border-radius:6px;cursor:pointer;display:flex;height:32px;justify-content:center;transition:background .2s ease;width:32px}.lexical-text-editor-link .link-editor-btn:hover{background:#f3f4f6}.Lexical-Tooltip-Wrapper{display:inline-block;position:relative}.Lexical-Tooltip-Tip{background:#5a5a5a;border-radius:4px;color:#fff;font-family:sans-serif;font-size:12px;left:50%;line-height:1;padding:8px 12px;position:absolute;transform:translateX(-50%);transition:all .5s;white-space:nowrap;z-index:100}.Lexical-Tooltip-Tip:before{border:6px solid transparent;content:" ";height:0;left:50%;margin-left:-6px;pointer-events:none;position:absolute;width:0}.Lexical-Tooltip-Tip.top{top:-35px}.Lexical-Tooltip-Tip.top:before{border-top-color:#5a5a5a;top:100%}.Lexical-Tooltip-Tip.right{left:calc(100% + 30px);top:50%;transform:translateX(0) translateY(-50%)}.Lexical-Tooltip-Tip.right:before{border-right-color:#5a5a5a;left:-6px;top:50%;transform:translateX(0) translateY(-50%)}.Lexical-Tooltip-Tip.bottom{bottom:-35px}.Lexical-Tooltip-Tip.bottom:before{border-bottom-color:#5a5a5a;bottom:100%}.Lexical-Tooltip-Tip.left{left:auto;right:calc(100% + 30px);top:50%;transform:translateX(0) translateY(-50%)}.Lexical-Tooltip-Tip.left:before{border-left-color:#5a5a5a;left:auto;right:-12px;top:50%;transform:translateX(0) translateY(-50%)}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DOMConversionMap, NodeKey, TextNode, SerializedTextNode, LexicalNode } from 'lexical';
|
|
2
|
+
export declare class ExtendedTextNode extends TextNode {
|
|
3
|
+
constructor(text: string, key?: NodeKey);
|
|
4
|
+
static getType(): string;
|
|
5
|
+
static clone(node: ExtendedTextNode): ExtendedTextNode;
|
|
6
|
+
static importDOM(): DOMConversionMap | null;
|
|
7
|
+
static importJSON(serializedNode: SerializedTextNode): ExtendedTextNode;
|
|
8
|
+
isSimpleText(): boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function $createExtendedTextNode(text?: string): ExtendedTextNode;
|
|
11
|
+
export declare function $isExtendedTextNode(node: LexicalNode | null | undefined): node is ExtendedTextNode;
|
|
@@ -38,6 +38,6 @@ export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
38
38
|
exportJSON(): SerializedImageNode;
|
|
39
39
|
static importJSON(serializedNode: SerializedImageNode): ImageNode;
|
|
40
40
|
updateDimensions(width: number, height: number): void;
|
|
41
|
-
updateDOM(): boolean;
|
|
41
|
+
updateDOM(prevNode: ImageNode): boolean;
|
|
42
42
|
decorate(): JSX.Element;
|
|
43
43
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function YoutubePlugin(): import("react/jsx-runtime").JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innoviatech/lexical-text-editor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
"require": "./dist/index.js",
|
|
17
17
|
"types": "./dist/index.d.ts"
|
|
18
18
|
},
|
|
19
|
-
"./style.css":
|
|
19
|
+
"./style.css": {
|
|
20
|
+
"import": "./dist/lexical-editor.css",
|
|
21
|
+
"require": "./dist/lexical-editor.css"
|
|
22
|
+
}
|
|
20
23
|
},
|
|
21
24
|
"scripts": {
|
|
22
25
|
"build": "rollup -c",
|
|
@@ -24,31 +27,32 @@
|
|
|
24
27
|
"prepublishOnly": "npm run build"
|
|
25
28
|
},
|
|
26
29
|
"peerDependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"lexical": "^0.36.2",
|
|
30
|
+
"@lexical/code": "^0.36.2",
|
|
31
|
+
"@lexical/link": "^0.36.2",
|
|
32
|
+
"@lexical/list": "^0.36.2",
|
|
30
33
|
"@lexical/react": "^0.36.2",
|
|
31
34
|
"@lexical/rich-text": "^0.36.2",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
+
"lexical": "^0.36.2",
|
|
36
|
+
"react": ">=18",
|
|
37
|
+
"react-color": "^2.19.3",
|
|
38
|
+
"react-dom": ">=18",
|
|
39
|
+
"react-icons": "^5.5.0"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
42
|
"@rollup/plugin-commonjs": "^28.0.0",
|
|
38
43
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
39
44
|
"@rollup/plugin-terser": "^0.4.0",
|
|
40
45
|
"@rollup/plugin-typescript": "^12.0.0",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"rollup-plugin-dts": "^6.1.0",
|
|
44
|
-
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
45
|
-
"rollup-plugin-postcss": "^4.0.2",
|
|
46
|
+
"@types/react": "^18.0.0",
|
|
47
|
+
"@types/react-dom": "^18.0.0",
|
|
46
48
|
"autoprefixer": "^10.4.0",
|
|
47
49
|
"postcss": "^8.4.0",
|
|
48
|
-
"tailwindcss": "^3.3.0",
|
|
49
50
|
"react": "^18.0.0",
|
|
50
51
|
"react-dom": "^18.0.0",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
52
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
53
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
54
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
55
|
+
"tslib": "^2.6.0",
|
|
56
|
+
"typescript": "^5.0.0"
|
|
53
57
|
}
|
|
54
58
|
}
|
package/rollup.config.js
CHANGED
|
@@ -31,11 +31,10 @@ export default [
|
|
|
31
31
|
}),
|
|
32
32
|
commonjs(),
|
|
33
33
|
postcss({
|
|
34
|
-
extract: '
|
|
34
|
+
extract: 'lexical-editor.css',
|
|
35
35
|
minimize: true,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
36
|
+
inject: false,
|
|
37
|
+
modules: false
|
|
39
38
|
}),
|
|
40
39
|
typescript({
|
|
41
40
|
tsconfig: './tsconfig.json',
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Popover,
|
|
4
|
-
PopoverContent,
|
|
5
|
-
PopoverTrigger,
|
|
6
|
-
} from "./ui/popover"
|
|
1
|
+
|
|
2
|
+
|
|
7
3
|
import { RICH_ALIGNMENT_OPTIONS, RichTextAction } from "../constants/index";
|
|
8
4
|
|
|
9
|
-
import { useState } from "react"
|
|
5
|
+
import { useRef, useState } from "react"
|
|
10
6
|
import { HiChevronDown } from "react-icons/hi2";
|
|
7
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
|
|
11
8
|
|
|
12
9
|
interface Props {
|
|
13
10
|
onAction: (id: RichTextAction) => void;
|
|
@@ -18,26 +15,46 @@ interface Props {
|
|
|
18
15
|
export function AlignmentSelectionList({ onAction, alignmentSelectionMap }: Props) {
|
|
19
16
|
const activeAlignment = RICH_ALIGNMENT_OPTIONS.find(h => alignmentSelectionMap[h.id])
|
|
20
17
|
const [isOpen, setIsOpen] = useState(false)
|
|
18
|
+
const triggerRef = useRef<HTMLDivElement | null>(null);
|
|
19
|
+
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
21
20
|
return (
|
|
22
|
-
<Popover open={isOpen} onOpenChange={
|
|
23
|
-
<PopoverTrigger
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
|
22
|
+
<PopoverTrigger triggerRef={triggerRef}>
|
|
23
|
+
|
|
24
|
+
<button
|
|
25
|
+
className={`lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`}
|
|
26
|
+
onClick={() => setIsOpen((prev) => !prev)}
|
|
27
|
+
style={{
|
|
28
|
+
minWidth: 146
|
|
29
|
+
}}
|
|
26
30
|
>
|
|
27
|
-
{activeAlignment?.icon}
|
|
28
|
-
|
|
31
|
+
{activeAlignment?.icon}
|
|
32
|
+
<span>{activeAlignment?.label}</span>
|
|
33
|
+
<HiChevronDown className={`chevron ${isOpen ? "rotated" : ""}`} />
|
|
34
|
+
</button>
|
|
29
35
|
</PopoverTrigger>
|
|
30
|
-
<PopoverContent align="start"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
<PopoverContent open={isOpen} align="start" onClose={() => setIsOpen(false)} contentRef={contentRef}>
|
|
37
|
+
<div
|
|
38
|
+
style={{
|
|
39
|
+
display: 'flex', flexDirection: 'column', gap: 5
|
|
40
|
+
}}>
|
|
41
|
+
{
|
|
42
|
+
RICH_ALIGNMENT_OPTIONS.map(({ id, label, icon }) => (
|
|
43
|
+
<button
|
|
44
|
+
key={id}
|
|
45
|
+
className={`lexical-btn ${alignmentSelectionMap[id] ? "toolbar-active" : "toolbar"
|
|
46
|
+
}`}
|
|
47
|
+
onClick={() => {
|
|
48
|
+
onAction(id);
|
|
49
|
+
setIsOpen(false)
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
{icon}
|
|
53
|
+
<span className="label">{label}</span>
|
|
54
|
+
</button>
|
|
55
|
+
))
|
|
56
|
+
}
|
|
57
|
+
</div>
|
|
41
58
|
</PopoverContent>
|
|
42
59
|
</Popover>
|
|
43
60
|
)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
import { useState, useRef, useEffect } from "react";
|
|
3
2
|
import { SketchPicker } from "react-color";
|
|
4
|
-
import { Button } from "./ui/button";
|
|
5
3
|
import { createPortal } from "react-dom";
|
|
4
|
+
|
|
6
5
|
interface ColorPickerProps {
|
|
7
6
|
color: string;
|
|
8
7
|
onChange: (color: string) => void;
|
|
@@ -14,7 +13,6 @@ export default function ColorPicker({ color, onChange, icon }: ColorPickerProps)
|
|
|
14
13
|
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
15
14
|
const popoverRef = useRef<HTMLDivElement>(null);
|
|
16
15
|
|
|
17
|
-
// Close popover on outside click
|
|
18
16
|
useEffect(() => {
|
|
19
17
|
const handleClickOutside = (event: MouseEvent) => {
|
|
20
18
|
if (
|
|
@@ -30,33 +28,23 @@ export default function ColorPicker({ color, onChange, icon }: ColorPickerProps)
|
|
|
30
28
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
31
29
|
}, []);
|
|
32
30
|
|
|
33
|
-
// Prevent popover from stealing text selection focus
|
|
34
31
|
const preventFocus = (e: React.MouseEvent) => e.preventDefault();
|
|
35
32
|
|
|
36
33
|
return (
|
|
37
|
-
<div className="
|
|
38
|
-
<
|
|
34
|
+
<div className="color-picker-wrapper">
|
|
35
|
+
<button
|
|
39
36
|
ref={triggerRef}
|
|
40
|
-
|
|
41
|
-
size="icon"
|
|
42
|
-
className="rounded-md text-gray-700 hover:bg-gray-200"
|
|
43
|
-
aria-label="Change Color"
|
|
37
|
+
className={`size-8 lexical-btn ${open ? "toolbarActive" : "toolbar"} icon`}
|
|
44
38
|
onClick={() => setOpen((prev) => !prev)}
|
|
45
39
|
>
|
|
46
40
|
{icon}
|
|
47
|
-
</
|
|
41
|
+
</button>
|
|
48
42
|
|
|
49
43
|
{open &&
|
|
50
44
|
createPortal(
|
|
51
45
|
<div
|
|
52
46
|
ref={popoverRef}
|
|
53
|
-
className={`
|
|
54
|
-
absolute z-50 p-2 bg-transparent rounded-md select-none
|
|
55
|
-
transition-all duration-200
|
|
56
|
-
origin-top-left w-fit
|
|
57
|
-
${open ? "opacity-100 scale-100 translate-y-0"
|
|
58
|
-
: "opacity-0 scale-95 -translate-y-2 pointer-events-none"
|
|
59
|
-
}`}
|
|
47
|
+
className={`lexical-color-popover ${open ? "open" : ""}`}
|
|
60
48
|
style={{
|
|
61
49
|
top: triggerRef.current?.getBoundingClientRect().bottom,
|
|
62
50
|
left: triggerRef.current?.getBoundingClientRect().left,
|
|
@@ -68,13 +56,11 @@ export default function ColorPicker({ color, onChange, icon }: ColorPickerProps)
|
|
|
68
56
|
color={color}
|
|
69
57
|
onChangeComplete={(c: any) => {
|
|
70
58
|
onChange(c.hex);
|
|
71
|
-
// setOpen(false);
|
|
72
59
|
}}
|
|
73
60
|
/>
|
|
74
61
|
</div>,
|
|
75
62
|
document.body
|
|
76
|
-
)
|
|
77
|
-
}
|
|
63
|
+
)}
|
|
78
64
|
</div>
|
|
79
65
|
);
|
|
80
66
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "./ui/dialog";
|
|
3
|
-
import { Button } from "./ui/button";
|
|
4
1
|
import { useState } from "react";
|
|
5
2
|
import { VscPreview } from "react-icons/vsc";
|
|
3
|
+
import RawDialog from "./common/Dialog";
|
|
6
4
|
|
|
7
5
|
type HtmlPreviewProps = {
|
|
8
6
|
value: string;
|
|
@@ -11,7 +9,7 @@ type HtmlPreviewProps = {
|
|
|
11
9
|
export function HtmlPreview({ value }: HtmlPreviewProps) {
|
|
12
10
|
return (
|
|
13
11
|
<div
|
|
14
|
-
className="
|
|
12
|
+
className="lexical-text-editor-html-preview"
|
|
15
13
|
dangerouslySetInnerHTML={{ __html: value }}
|
|
16
14
|
/>
|
|
17
15
|
);
|
|
@@ -22,24 +20,33 @@ type ContentPreviewDialogProps = {
|
|
|
22
20
|
triggerLabel?: string;
|
|
23
21
|
};
|
|
24
22
|
|
|
25
|
-
export default function ContentPreviewDialog({
|
|
26
|
-
|
|
23
|
+
export default function ContentPreviewDialog({
|
|
24
|
+
value,
|
|
25
|
+
triggerLabel = "Preview",
|
|
26
|
+
}: ContentPreviewDialogProps) {
|
|
27
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
28
|
+
console.log(value);
|
|
27
29
|
return (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
<div className="lexical-text-editor-dialog">
|
|
31
|
+
{/* Trigger button */}
|
|
32
|
+
|
|
33
|
+
<button
|
|
34
|
+
className={`lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`}
|
|
35
|
+
onClick={() => setIsOpen((prev) => !prev)}
|
|
36
|
+
>
|
|
37
|
+
<VscPreview size={18} />
|
|
38
|
+
<span>{triggerLabel}</span>
|
|
39
|
+
</button>
|
|
40
|
+
|
|
41
|
+
{/* Dialog */}
|
|
42
|
+
<RawDialog open={isOpen} onClose={() => setIsOpen(false)} forPreview>
|
|
43
|
+
<div className="lte-dialog-header">Content Preview</div>
|
|
44
|
+
|
|
45
|
+
<div className="lte-preview-container">
|
|
46
|
+
<div className="lte-preview-title">CONTENT</div>
|
|
40
47
|
<HtmlPreview value={value} />
|
|
41
48
|
</div>
|
|
42
|
-
</
|
|
43
|
-
</
|
|
49
|
+
</RawDialog>
|
|
50
|
+
</div>
|
|
44
51
|
);
|
|
45
52
|
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { Button } from "./ui/button"
|
|
2
|
-
import {
|
|
3
|
-
Popover,
|
|
4
|
-
PopoverContent,
|
|
5
|
-
PopoverTrigger,
|
|
6
|
-
} from "./ui/popover"
|
|
7
1
|
import { RICH_TEXT_FORMAT_OPTIONS, RichTextAction } from "../constants/index";
|
|
8
|
-
import { useState } from "react"
|
|
2
|
+
import { useRef, useState } from "react"
|
|
9
3
|
import { HiChevronDown } from "react-icons/hi2";
|
|
4
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
|
|
10
5
|
|
|
11
6
|
interface Props {
|
|
12
7
|
onAction: (id: RichTextAction) => void,
|
|
@@ -16,26 +11,46 @@ interface Props {
|
|
|
16
11
|
}
|
|
17
12
|
export function DropdownList({ onAction, selectionMap }: Props) {
|
|
18
13
|
const [isOpen, setIsOpen] = useState(false)
|
|
14
|
+
const triggerRef = useRef<HTMLDivElement | null>(null);
|
|
15
|
+
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
19
16
|
return (
|
|
20
|
-
<Popover open={isOpen} onOpenChange={
|
|
21
|
-
<PopoverTrigger
|
|
22
|
-
<
|
|
23
|
-
|
|
17
|
+
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
|
18
|
+
<PopoverTrigger triggerRef={triggerRef}>
|
|
19
|
+
<button
|
|
20
|
+
className={`lexical-btn heading-trigger ${isOpen ? "toolbar-active" : "toolbar"}`}
|
|
21
|
+
onClick={() => setIsOpen((prev) => !prev)}
|
|
24
22
|
>
|
|
25
|
-
<span>Aa</span>
|
|
26
|
-
|
|
23
|
+
<span>Aa</span>
|
|
24
|
+
<HiChevronDown className={`chevron ${isOpen ? "rotated" : ""}`} />
|
|
25
|
+
</button>
|
|
27
26
|
</PopoverTrigger>
|
|
28
|
-
<PopoverContent
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
<PopoverContent open={isOpen} align="start" onClose={() => setIsOpen(false)} contentRef={contentRef}>
|
|
28
|
+
<div
|
|
29
|
+
style={{
|
|
30
|
+
display: 'flex', flexDirection: 'column', gap: 5
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
{
|
|
34
|
+
RICH_TEXT_FORMAT_OPTIONS.map(({ id, label, icon }) => (
|
|
35
|
+
<button
|
|
36
|
+
key={id}
|
|
37
|
+
className={`lexical-btn ${selectionMap[id] ? "toolbar-active" : "toolbar"
|
|
38
|
+
}`}
|
|
39
|
+
onClick={() => {
|
|
40
|
+
onAction(id);
|
|
41
|
+
setIsOpen(false)
|
|
42
|
+
}}
|
|
43
|
+
style={{
|
|
44
|
+
minWidth: 130
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
{icon}
|
|
48
|
+
<span className="label">{label}</span>
|
|
49
|
+
</button>
|
|
50
|
+
))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
</div>
|
|
39
54
|
</PopoverContent>
|
|
40
55
|
</Popover>
|
|
41
56
|
)
|
|
@@ -1,45 +1,61 @@
|
|
|
1
|
-
import { Button } from "./ui/button"
|
|
2
|
-
import {
|
|
3
|
-
Popover,
|
|
4
|
-
PopoverContent,
|
|
5
|
-
PopoverTrigger,
|
|
6
|
-
} from "./ui/popover"
|
|
7
1
|
import { HEADINGS } from "../constants/index";
|
|
8
|
-
import { type HeadingTagType } from
|
|
9
|
-
|
|
10
|
-
import { useState } from "react"
|
|
2
|
+
import { type HeadingTagType } from "@lexical/rich-text";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
11
4
|
import { HiChevronDown } from "react-icons/hi2";
|
|
5
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./common/Popover";
|
|
6
|
+
|
|
12
7
|
|
|
13
8
|
interface Props {
|
|
14
|
-
updateHeading: (heading: HeadingTagType | "normal") => void
|
|
15
|
-
headingSelectionMap: {
|
|
16
|
-
[id: string]: boolean;
|
|
17
|
-
}
|
|
9
|
+
updateHeading: (heading: HeadingTagType | "normal") => void;
|
|
10
|
+
headingSelectionMap: { [id: string]: boolean };
|
|
18
11
|
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
19
15
|
export function HeadingSelectionList({ updateHeading, headingSelectionMap }: Props) {
|
|
20
|
-
const activeHeading = HEADINGS.find(h => headingSelectionMap[h.id])
|
|
21
|
-
const [
|
|
16
|
+
const activeHeading = HEADINGS.find((h) => headingSelectionMap[h.id]);
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
const triggerRef = useRef<HTMLDivElement | null>(null);
|
|
19
|
+
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
20
|
+
|
|
22
21
|
return (
|
|
23
|
-
<Popover open={
|
|
24
|
-
<PopoverTrigger
|
|
25
|
-
<
|
|
26
|
-
|
|
22
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
23
|
+
<PopoverTrigger triggerRef={triggerRef}>
|
|
24
|
+
<button
|
|
25
|
+
className={`lexical-btn heading-trigger ${open ? "toolbar-active" : "toolbar"}`}
|
|
26
|
+
onClick={() => setOpen((prev) => !prev)}
|
|
27
|
+
style={{
|
|
28
|
+
minWidth: 132
|
|
29
|
+
}}
|
|
27
30
|
>
|
|
28
|
-
{activeHeading?.icon}
|
|
29
|
-
|
|
31
|
+
{activeHeading?.icon}
|
|
32
|
+
<span>{activeHeading?.label}</span>
|
|
33
|
+
<HiChevronDown className={`chevron ${open ? "rotated" : ""}`} />
|
|
34
|
+
</button>
|
|
30
35
|
</PopoverTrigger>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
|
|
37
|
+
<PopoverContent open={open} align="start" onClose={() => setOpen(false)} contentRef={contentRef}>
|
|
38
|
+
<div
|
|
39
|
+
style={{
|
|
40
|
+
display: 'flex', flexDirection: 'column', gap: 5
|
|
41
|
+
}}>
|
|
42
|
+
{HEADINGS.map(({ id, label, icon }) => (
|
|
43
|
+
<button
|
|
44
|
+
key={id}
|
|
45
|
+
className={`lexical-btn ${headingSelectionMap[id] ? "toolbar-active" : "toolbar"
|
|
46
|
+
}`}
|
|
47
|
+
onClick={() => {
|
|
48
|
+
updateHeading(id as HeadingTagType | "normal");
|
|
49
|
+
setOpen(false);
|
|
50
|
+
}}
|
|
37
51
|
>
|
|
38
|
-
{icon}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
{icon}
|
|
53
|
+
<span className="label">{label}</span>
|
|
54
|
+
</button>
|
|
55
|
+
))}
|
|
56
|
+
</div>
|
|
42
57
|
</PopoverContent>
|
|
43
58
|
</Popover>
|
|
44
|
-
|
|
59
|
+
|
|
60
|
+
);
|
|
45
61
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
2
|
import { $getNodeByKey, type NodeKey } from "lexical";
|
|
3
|
-
import { useRef
|
|
3
|
+
import { useRef } from "react";
|
|
4
4
|
|
|
5
5
|
type ImageComponentProps = {
|
|
6
6
|
src: string;
|
|
@@ -20,10 +20,9 @@ export const ImageComponent: React.FC<ImageComponentProps> = ({
|
|
|
20
20
|
maxWidth,
|
|
21
21
|
}) => {
|
|
22
22
|
const [editor] = useLexicalComposerContext();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
23
|
+
|
|
24
|
+
const dragSizeRef = useRef<{ width: number; height: number, ratio: number } | null>(null);
|
|
25
|
+
|
|
27
26
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
28
27
|
const startPos = useRef<{
|
|
29
28
|
x: number;
|
|
@@ -35,36 +34,70 @@ export const ImageComponent: React.FC<ImageComponentProps> = ({
|
|
|
35
34
|
const onMouseDown = (e: React.MouseEvent) => {
|
|
36
35
|
e.preventDefault();
|
|
37
36
|
e.stopPropagation();
|
|
37
|
+
|
|
38
|
+
const img = wrapperRef.current?.querySelector("img");
|
|
39
|
+
if (!img) return;
|
|
40
|
+
|
|
41
|
+
const renderedWidth = img.getBoundingClientRect().width;
|
|
42
|
+
const naturalRatio = img.naturalHeight / img.naturalWidth;
|
|
43
|
+
const renderedHeight = renderedWidth * naturalRatio;
|
|
44
|
+
|
|
38
45
|
startPos.current = {
|
|
39
46
|
x: e.clientX,
|
|
40
47
|
y: e.clientY,
|
|
41
|
-
width:
|
|
42
|
-
height:
|
|
48
|
+
width: renderedWidth,
|
|
49
|
+
height: renderedHeight,
|
|
43
50
|
};
|
|
51
|
+
|
|
52
|
+
dragSizeRef.current = {
|
|
53
|
+
width: renderedWidth,
|
|
54
|
+
height: renderedHeight,
|
|
55
|
+
ratio: naturalRatio,
|
|
56
|
+
};
|
|
57
|
+
|
|
44
58
|
window.addEventListener("mousemove", onMouseMove);
|
|
45
59
|
window.addEventListener("mouseup", onMouseUp);
|
|
46
60
|
};
|
|
47
61
|
|
|
62
|
+
|
|
63
|
+
|
|
48
64
|
const onMouseMove = (e: MouseEvent) => {
|
|
49
|
-
if (!startPos.current) return;
|
|
65
|
+
if (!startPos.current || !dragSizeRef.current) return;
|
|
66
|
+
|
|
50
67
|
const deltaX = e.clientX - startPos.current.x;
|
|
51
|
-
const newWidth = Math.min(
|
|
52
|
-
|
|
53
|
-
(
|
|
54
|
-
|
|
68
|
+
const newWidth = Math.min(
|
|
69
|
+
maxWidth,
|
|
70
|
+
Math.max(50, startPos.current.width + deltaX)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const newHeight = newWidth * dragSizeRef.current.ratio;
|
|
74
|
+
|
|
75
|
+
dragSizeRef.current.width = newWidth;
|
|
76
|
+
dragSizeRef.current.height = newHeight;
|
|
77
|
+
|
|
78
|
+
const img = wrapperRef.current?.querySelector("img");
|
|
79
|
+
if (img) {
|
|
80
|
+
img.style.width = newWidth + "px";
|
|
81
|
+
img.style.height = newHeight + "px";
|
|
82
|
+
}
|
|
55
83
|
};
|
|
56
84
|
|
|
85
|
+
|
|
57
86
|
const onMouseUp = () => {
|
|
58
|
-
if (!
|
|
87
|
+
if (!dragSizeRef.current) return;
|
|
88
|
+
|
|
89
|
+
const { width: finalWidth, height: finalHeight } = dragSizeRef.current;
|
|
59
90
|
|
|
60
91
|
editor.update(() => {
|
|
61
92
|
const node = $getNodeByKey(nodeKey);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(node as any).updateDimensions(currentSize.width as number, currentSize.height as number);
|
|
93
|
+
if (node && typeof (node as any).updateDimensions === "function") {
|
|
94
|
+
(node as any).updateDimensions(finalWidth, finalHeight);
|
|
65
95
|
}
|
|
66
96
|
});
|
|
67
97
|
|
|
98
|
+
dragSizeRef.current = null;
|
|
99
|
+
startPos.current = null;
|
|
100
|
+
|
|
68
101
|
window.removeEventListener("mousemove", onMouseMove);
|
|
69
102
|
window.removeEventListener("mouseup", onMouseUp);
|
|
70
103
|
};
|
|
@@ -81,9 +114,9 @@ export const ImageComponent: React.FC<ImageComponentProps> = ({
|
|
|
81
114
|
<img
|
|
82
115
|
src={src}
|
|
83
116
|
alt={altText}
|
|
117
|
+
width={width === "inherit" ? undefined : width}
|
|
118
|
+
height={height === "inherit" ? undefined : height}
|
|
84
119
|
style={{
|
|
85
|
-
width: currentSize.width,
|
|
86
|
-
height: currentSize.height,
|
|
87
120
|
maxWidth: "100%",
|
|
88
121
|
display: "block",
|
|
89
122
|
}}
|
|
@@ -104,4 +137,4 @@ export const ImageComponent: React.FC<ImageComponentProps> = ({
|
|
|
104
137
|
/>
|
|
105
138
|
</div>
|
|
106
139
|
);
|
|
107
|
-
};
|
|
140
|
+
};
|