@thangph2146/lexical-editor 0.0.1
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/dist/editor-x/editor.cjs +33121 -0
- package/dist/editor-x/editor.cjs.map +1 -0
- package/dist/editor-x/editor.css +2854 -0
- package/dist/editor-x/editor.css.map +1 -0
- package/dist/editor-x/editor.d.cts +12 -0
- package/dist/editor-x/editor.d.ts +12 -0
- package/dist/editor-x/editor.js +33095 -0
- package/dist/editor-x/editor.js.map +1 -0
- package/dist/index.cjs +33210 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +2854 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +33183 -0
- package/dist/index.js.map +1 -0
- package/package.json +84 -0
- package/src/components/lexical-editor.tsx +123 -0
- package/src/context/editor-container-context.tsx +29 -0
- package/src/context/priority-image-context.tsx +7 -0
- package/src/context/toolbar-context.tsx +60 -0
- package/src/context/uploads-context.tsx +53 -0
- package/src/editor-hooks/use-debounce.ts +80 -0
- package/src/editor-hooks/use-modal.tsx +64 -0
- package/src/editor-hooks/use-report.ts +57 -0
- package/src/editor-hooks/use-update-toolbar.ts +41 -0
- package/src/editor-ui/broken-image.tsx +18 -0
- package/src/editor-ui/caption-composer.tsx +45 -0
- package/src/editor-ui/code-button.tsx +75 -0
- package/src/editor-ui/color-picker.tsx +2010 -0
- package/src/editor-ui/content-editable.tsx +37 -0
- package/src/editor-ui/hooks/use-image-caption-controls.ts +118 -0
- package/src/editor-ui/hooks/use-image-node-interactions.ts +245 -0
- package/src/editor-ui/hooks/use-responsive-image-dimensions.ts +202 -0
- package/src/editor-ui/image-component.tsx +321 -0
- package/src/editor-ui/image-placeholder.tsx +57 -0
- package/src/editor-ui/image-resizer.tsx +499 -0
- package/src/editor-ui/image-sizing.ts +120 -0
- package/src/editor-ui/lazy-image.tsx +136 -0
- package/src/editor-x/editor.tsx +117 -0
- package/src/editor-x/nodes.ts +79 -0
- package/src/editor-x/plugins.tsx +380 -0
- package/src/hooks/use-click-outside.ts +27 -0
- package/src/hooks/use-element-size.ts +54 -0
- package/src/hooks/use-header-height.ts +95 -0
- package/src/hooks/use-isomorphic-layout-effect.ts +4 -0
- package/src/index.ts +4 -0
- package/src/lib/logger.ts +6 -0
- package/src/lib/utils.ts +19 -0
- package/src/nodes/autocomplete-node.tsx +94 -0
- package/src/nodes/embeds/tweet-node.tsx +224 -0
- package/src/nodes/embeds/youtube-node.tsx +519 -0
- package/src/nodes/emoji-node.tsx +83 -0
- package/src/nodes/image-node.tsx +328 -0
- package/src/nodes/keyword-node.tsx +58 -0
- package/src/nodes/layout-container-node.tsx +128 -0
- package/src/nodes/layout-item-node.tsx +118 -0
- package/src/nodes/list-with-color-node.tsx +160 -0
- package/src/nodes/mention-node.ts +122 -0
- package/src/plugins/actions/actions-plugin.tsx +3 -0
- package/src/plugins/actions/character-limit-plugin.tsx +27 -0
- package/src/plugins/actions/clear-editor-plugin.tsx +70 -0
- package/src/plugins/actions/counter-character-plugin.tsx +80 -0
- package/src/plugins/actions/edit-mode-toggle-plugin.tsx +49 -0
- package/src/plugins/actions/import-export-plugin.tsx +61 -0
- package/src/plugins/actions/markdown-toggle-plugin.tsx +78 -0
- package/src/plugins/actions/max-length-plugin.tsx +59 -0
- package/src/plugins/actions/share-content-plugin.tsx +72 -0
- package/src/plugins/actions/speech-to-text-plugin.tsx +159 -0
- package/src/plugins/actions/tree-view-plugin.tsx +63 -0
- package/src/plugins/align-plugin.tsx +86 -0
- package/src/plugins/auto-link-plugin.tsx +34 -0
- package/src/plugins/autocomplete-plugin.tsx +2574 -0
- package/src/plugins/code-action-menu-plugin.tsx +240 -0
- package/src/plugins/code-highlight-plugin.tsx +22 -0
- package/src/plugins/component-picker-menu-plugin.tsx +427 -0
- package/src/plugins/context-menu-plugin.tsx +311 -0
- package/src/plugins/drag-drop-paste-plugin.tsx +52 -0
- package/src/plugins/draggable-block-plugin.tsx +50 -0
- package/src/plugins/embeds/auto-embed-plugin.tsx +324 -0
- package/src/plugins/embeds/twitter-plugin.tsx +45 -0
- package/src/plugins/embeds/youtube-plugin.tsx +84 -0
- package/src/plugins/emoji-picker-plugin.tsx +206 -0
- package/src/plugins/emojis-plugin.tsx +84 -0
- package/src/plugins/floating-link-editor-plugin.tsx +791 -0
- package/src/plugins/floating-text-format-plugin.tsx +710 -0
- package/src/plugins/images-plugin.tsx +671 -0
- package/src/plugins/keywords-plugin.tsx +59 -0
- package/src/plugins/layout-plugin.tsx +658 -0
- package/src/plugins/link-plugin.tsx +18 -0
- package/src/plugins/list-color-plugin.tsx +178 -0
- package/src/plugins/list-max-indent-level-plugin.tsx +85 -0
- package/src/plugins/mentions-plugin.tsx +714 -0
- package/src/plugins/picker/alignment-picker-plugin.tsx +40 -0
- package/src/plugins/picker/bulleted-list-picker-plugin.tsx +14 -0
- package/src/plugins/picker/check-list-picker-plugin.tsx +14 -0
- package/src/plugins/picker/code-picker-plugin.tsx +30 -0
- package/src/plugins/picker/columns-layout-picker-plugin.tsx +16 -0
- package/src/plugins/picker/component-picker-option.tsx +47 -0
- package/src/plugins/picker/divider-picker-plugin.tsx +14 -0
- package/src/plugins/picker/embeds-picker-plugin.tsx +24 -0
- package/src/plugins/picker/heading-picker-plugin.tsx +32 -0
- package/src/plugins/picker/image-picker-plugin.tsx +16 -0
- package/src/plugins/picker/numbered-list-picker-plugin.tsx +14 -0
- package/src/plugins/picker/paragraph-picker-plugin.tsx +20 -0
- package/src/plugins/picker/quote-picker-plugin.tsx +21 -0
- package/src/plugins/picker/table-picker-plugin.tsx +56 -0
- package/src/plugins/tab-focus-plugin.tsx +66 -0
- package/src/plugins/table-column-resizer-plugin.tsx +309 -0
- package/src/plugins/table-plugin.tsx +299 -0
- package/src/plugins/toolbar/block-format/block-format-data.tsx +69 -0
- package/src/plugins/toolbar/block-format/format-bulleted-list.tsx +40 -0
- package/src/plugins/toolbar/block-format/format-check-list.tsx +40 -0
- package/src/plugins/toolbar/block-format/format-code-block.tsx +45 -0
- package/src/plugins/toolbar/block-format/format-heading.tsx +34 -0
- package/src/plugins/toolbar/block-format/format-list-with-marker.tsx +74 -0
- package/src/plugins/toolbar/block-format/format-numbered-list.tsx +40 -0
- package/src/plugins/toolbar/block-format/format-paragraph.tsx +31 -0
- package/src/plugins/toolbar/block-format/format-quote.tsx +32 -0
- package/src/plugins/toolbar/block-format-toolbar-plugin.tsx +117 -0
- package/src/plugins/toolbar/block-insert/insert-columns-layout.tsx +32 -0
- package/src/plugins/toolbar/block-insert/insert-embeds.tsx +31 -0
- package/src/plugins/toolbar/block-insert/insert-horizontal-rule.tsx +30 -0
- package/src/plugins/toolbar/block-insert/insert-image.tsx +32 -0
- package/src/plugins/toolbar/block-insert/insert-table.tsx +32 -0
- package/src/plugins/toolbar/block-insert-plugin.tsx +30 -0
- package/src/plugins/toolbar/clear-formatting-toolbar-plugin.tsx +92 -0
- package/src/plugins/toolbar/code-language-toolbar-plugin.tsx +121 -0
- package/src/plugins/toolbar/element-format-toolbar-plugin.tsx +251 -0
- package/src/plugins/toolbar/font-background-toolbar-plugin.tsx +179 -0
- package/src/plugins/toolbar/font-color-toolbar-plugin.tsx +101 -0
- package/src/plugins/toolbar/font-family-toolbar-plugin.tsx +91 -0
- package/src/plugins/toolbar/font-format-toolbar-plugin.tsx +85 -0
- package/src/plugins/toolbar/font-size-toolbar-plugin.tsx +177 -0
- package/src/plugins/toolbar/history-toolbar-plugin.tsx +87 -0
- package/src/plugins/toolbar/link-toolbar-plugin.tsx +90 -0
- package/src/plugins/toolbar/subsuper-toolbar-plugin.tsx +69 -0
- package/src/plugins/toolbar/toolbar-plugin.tsx +66 -0
- package/src/plugins/typing-pref-plugin.tsx +118 -0
- package/src/shared/can-use-dom.ts +4 -0
- package/src/shared/environment.ts +47 -0
- package/src/shared/invariant.ts +16 -0
- package/src/shared/use-layout-effect.ts +12 -0
- package/src/themes/_mixins.scss +107 -0
- package/src/themes/_variables.scss +33 -0
- package/src/themes/editor-theme.scss +622 -0
- package/src/themes/editor-theme.ts +118 -0
- package/src/themes/plugins.scss +1180 -0
- package/src/themes/ui-components.scss +936 -0
- package/src/transformers/markdown-emoji-transformer.ts +20 -0
- package/src/transformers/markdown-hr-transformer.ts +28 -0
- package/src/transformers/markdown-image-transformer.ts +31 -0
- package/src/transformers/markdown-list-transformer.ts +51 -0
- package/src/transformers/markdown-table-transformer.ts +200 -0
- package/src/transformers/markdown-tweet-transformer.ts +26 -0
- package/src/ui/button-group.tsx +10 -0
- package/src/ui/button.tsx +29 -0
- package/src/ui/collapsible.tsx +67 -0
- package/src/ui/command.tsx +48 -0
- package/src/ui/dialog.tsx +146 -0
- package/src/ui/flex.tsx +38 -0
- package/src/ui/input.tsx +20 -0
- package/src/ui/label.tsx +20 -0
- package/src/ui/popover.tsx +128 -0
- package/src/ui/scroll-area.tsx +17 -0
- package/src/ui/select.tsx +171 -0
- package/src/ui/separator.tsx +20 -0
- package/src/ui/slider.tsx +14 -0
- package/src/ui/slot.tsx +3 -0
- package/src/ui/tabs.tsx +87 -0
- package/src/ui/toggle-group.tsx +109 -0
- package/src/ui/toggle.tsx +28 -0
- package/src/ui/tooltip.tsx +28 -0
- package/src/ui/typography.tsx +44 -0
- package/src/utils/doc-serialization.ts +68 -0
- package/src/utils/emoji-list.ts +16604 -0
- package/src/utils/get-dom-range-rect.ts +20 -0
- package/src/utils/get-selected-node.ts +20 -0
- package/src/utils/is-mobile-width.ts +0 -0
- package/src/utils/set-floating-elem-position-for-link-editor.ts +39 -0
- package/src/utils/set-floating-elem-position.ts +44 -0
- package/src/utils/swipe.ts +119 -0
- package/src/utils/url.ts +32 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cn } from "../lib/utils"
|
|
3
|
+
|
|
4
|
+
export const TooltipProvider = ({ children }: { children: React.ReactNode }) => <>{children}</>
|
|
5
|
+
|
|
6
|
+
export const Tooltip = ({ children }: { children: React.ReactNode, disableHoverableContent?: boolean }) => <div className="editor-tooltip-group">{children}</div>
|
|
7
|
+
|
|
8
|
+
export const TooltipTrigger = ({ asChild, children, ...props }: React.HTMLAttributes<HTMLElement> & { asChild?: boolean, children: React.ReactNode }) => {
|
|
9
|
+
const child = asChild ? React.Children.only(children) : children
|
|
10
|
+
if (!React.isValidElement(child)) return null
|
|
11
|
+
return React.cloneElement(child as React.ReactElement<any>, {
|
|
12
|
+
...props,
|
|
13
|
+
className: cn((child as React.ReactElement<any>).props.className, "editor-tooltip-trigger")
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const TooltipContent = ({ children, className, side = "top", ...props }: React.HTMLAttributes<HTMLDivElement> & { side?: "top" | "bottom" | "left" | "right" }) => (
|
|
18
|
+
<div
|
|
19
|
+
className={cn(
|
|
20
|
+
"editor-tooltip-content",
|
|
21
|
+
`editor-tooltip-content--${side}`,
|
|
22
|
+
className
|
|
23
|
+
)}
|
|
24
|
+
{...props}
|
|
25
|
+
>
|
|
26
|
+
{children}
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cn } from "../lib/utils"
|
|
3
|
+
|
|
4
|
+
export const IconSize = ({ size = "medium", children, className }: { size?: "small" | "medium" | "large" | "sm" | "md" | "lg" | "xs" | "xl", children: React.ReactNode, className?: string }) => {
|
|
5
|
+
const sizeMap: Record<string, string> = {
|
|
6
|
+
xs: "editor-icon-xs",
|
|
7
|
+
small: "editor-icon-sm",
|
|
8
|
+
medium: "editor-icon-md",
|
|
9
|
+
large: "editor-icon-lg",
|
|
10
|
+
xl: "editor-icon-xl",
|
|
11
|
+
sm: "editor-icon-sm",
|
|
12
|
+
md: "editor-icon-md",
|
|
13
|
+
lg: "editor-icon-lg",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (React.isValidElement(children)) {
|
|
17
|
+
return React.cloneElement(children as React.ReactElement<React.HTMLAttributes<HTMLElement>>, {
|
|
18
|
+
className: cn(sizeMap[size] || sizeMap.medium, (children as React.ReactElement<React.HTMLAttributes<HTMLElement>>).props.className, className)
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return <>{children}</>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const TypographyP = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
|
26
|
+
({ className, ...props }, ref) => (
|
|
27
|
+
<p ref={ref} className={cn("editor-typography-p", className)} {...props} />
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
TypographyP.displayName = "TypographyP"
|
|
31
|
+
|
|
32
|
+
export const TypographyPSmall = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
|
33
|
+
({ className, ...props }, ref) => (
|
|
34
|
+
<p ref={ref} className={cn("editor-typography-p-small", className)} {...props} />
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
TypographyPSmall.displayName = "TypographyPSmall"
|
|
38
|
+
|
|
39
|
+
export const TypographySpanSmallMuted = React.forwardRef<HTMLSpanElement, React.HTMLAttributes<HTMLSpanElement>>(
|
|
40
|
+
({ className, ...props }, ref) => (
|
|
41
|
+
<span ref={ref} className={cn("editor-typography-span-small-muted", className)} {...props} />
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
TypographySpanSmallMuted.displayName = "TypographySpanSmallMuted"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { SerializedDocument } from "@lexical/file"
|
|
2
|
+
|
|
3
|
+
async function* generateReader<T = unknown>(
|
|
4
|
+
reader: ReadableStreamDefaultReader<T>
|
|
5
|
+
) {
|
|
6
|
+
let done = false
|
|
7
|
+
while (!done) {
|
|
8
|
+
const res = await reader.read()
|
|
9
|
+
const { value } = res
|
|
10
|
+
if (value !== undefined) {
|
|
11
|
+
yield value
|
|
12
|
+
}
|
|
13
|
+
done = res.done
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function readBytestoString(
|
|
18
|
+
reader: ReadableStreamDefaultReader
|
|
19
|
+
): Promise<string> {
|
|
20
|
+
const output = []
|
|
21
|
+
const chunkSize = 0x8000
|
|
22
|
+
for await (const value of generateReader(reader)) {
|
|
23
|
+
for (let i = 0; i < value.length; i += chunkSize) {
|
|
24
|
+
output.push(String.fromCharCode(...value.subarray(i, i + chunkSize)))
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return output.join("")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function docToHash(doc: SerializedDocument): Promise<string> {
|
|
31
|
+
const cs = new CompressionStream("gzip")
|
|
32
|
+
const writer = cs.writable.getWriter()
|
|
33
|
+
const [, output] = await Promise.all([
|
|
34
|
+
writer
|
|
35
|
+
.write(new TextEncoder().encode(JSON.stringify(doc)))
|
|
36
|
+
.then(() => writer.close()),
|
|
37
|
+
readBytestoString(cs.readable.getReader()),
|
|
38
|
+
])
|
|
39
|
+
return `#doc=${btoa(output)
|
|
40
|
+
.replace(/\//g, "_")
|
|
41
|
+
.replace(/\+/g, "-")
|
|
42
|
+
.replace(/=+$/, "")}`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function docFromHash(
|
|
46
|
+
hash: string
|
|
47
|
+
): Promise<SerializedDocument | null> {
|
|
48
|
+
const m = /^#doc=(.*)$/.exec(hash)
|
|
49
|
+
if (!m || !m[1]) {
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
const ds = new DecompressionStream("gzip")
|
|
53
|
+
const writer = ds.writable.getWriter()
|
|
54
|
+
const b64 = atob(m[1].replace(/_/g, "/").replace(/-/g, "+"))
|
|
55
|
+
const array = new Uint8Array(b64.length)
|
|
56
|
+
for (let i = 0; i < b64.length; i++) {
|
|
57
|
+
array[i] = b64.charCodeAt(i)
|
|
58
|
+
}
|
|
59
|
+
const closed = writer.write(array).then(() => writer.close())
|
|
60
|
+
const output = []
|
|
61
|
+
for await (const chunk of generateReader(
|
|
62
|
+
ds.readable.pipeThrough(new TextDecoderStream()).getReader()
|
|
63
|
+
)) {
|
|
64
|
+
output.push(chunk)
|
|
65
|
+
}
|
|
66
|
+
await closed
|
|
67
|
+
return JSON.parse(output.join(""))
|
|
68
|
+
}
|