@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.
Files changed (183) hide show
  1. package/dist/editor-x/editor.cjs +33121 -0
  2. package/dist/editor-x/editor.cjs.map +1 -0
  3. package/dist/editor-x/editor.css +2854 -0
  4. package/dist/editor-x/editor.css.map +1 -0
  5. package/dist/editor-x/editor.d.cts +12 -0
  6. package/dist/editor-x/editor.d.ts +12 -0
  7. package/dist/editor-x/editor.js +33095 -0
  8. package/dist/editor-x/editor.js.map +1 -0
  9. package/dist/index.cjs +33210 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.css +2854 -0
  12. package/dist/index.css.map +1 -0
  13. package/dist/index.d.cts +15 -0
  14. package/dist/index.d.ts +15 -0
  15. package/dist/index.js +33183 -0
  16. package/dist/index.js.map +1 -0
  17. package/package.json +84 -0
  18. package/src/components/lexical-editor.tsx +123 -0
  19. package/src/context/editor-container-context.tsx +29 -0
  20. package/src/context/priority-image-context.tsx +7 -0
  21. package/src/context/toolbar-context.tsx +60 -0
  22. package/src/context/uploads-context.tsx +53 -0
  23. package/src/editor-hooks/use-debounce.ts +80 -0
  24. package/src/editor-hooks/use-modal.tsx +64 -0
  25. package/src/editor-hooks/use-report.ts +57 -0
  26. package/src/editor-hooks/use-update-toolbar.ts +41 -0
  27. package/src/editor-ui/broken-image.tsx +18 -0
  28. package/src/editor-ui/caption-composer.tsx +45 -0
  29. package/src/editor-ui/code-button.tsx +75 -0
  30. package/src/editor-ui/color-picker.tsx +2010 -0
  31. package/src/editor-ui/content-editable.tsx +37 -0
  32. package/src/editor-ui/hooks/use-image-caption-controls.ts +118 -0
  33. package/src/editor-ui/hooks/use-image-node-interactions.ts +245 -0
  34. package/src/editor-ui/hooks/use-responsive-image-dimensions.ts +202 -0
  35. package/src/editor-ui/image-component.tsx +321 -0
  36. package/src/editor-ui/image-placeholder.tsx +57 -0
  37. package/src/editor-ui/image-resizer.tsx +499 -0
  38. package/src/editor-ui/image-sizing.ts +120 -0
  39. package/src/editor-ui/lazy-image.tsx +136 -0
  40. package/src/editor-x/editor.tsx +117 -0
  41. package/src/editor-x/nodes.ts +79 -0
  42. package/src/editor-x/plugins.tsx +380 -0
  43. package/src/hooks/use-click-outside.ts +27 -0
  44. package/src/hooks/use-element-size.ts +54 -0
  45. package/src/hooks/use-header-height.ts +95 -0
  46. package/src/hooks/use-isomorphic-layout-effect.ts +4 -0
  47. package/src/index.ts +4 -0
  48. package/src/lib/logger.ts +6 -0
  49. package/src/lib/utils.ts +19 -0
  50. package/src/nodes/autocomplete-node.tsx +94 -0
  51. package/src/nodes/embeds/tweet-node.tsx +224 -0
  52. package/src/nodes/embeds/youtube-node.tsx +519 -0
  53. package/src/nodes/emoji-node.tsx +83 -0
  54. package/src/nodes/image-node.tsx +328 -0
  55. package/src/nodes/keyword-node.tsx +58 -0
  56. package/src/nodes/layout-container-node.tsx +128 -0
  57. package/src/nodes/layout-item-node.tsx +118 -0
  58. package/src/nodes/list-with-color-node.tsx +160 -0
  59. package/src/nodes/mention-node.ts +122 -0
  60. package/src/plugins/actions/actions-plugin.tsx +3 -0
  61. package/src/plugins/actions/character-limit-plugin.tsx +27 -0
  62. package/src/plugins/actions/clear-editor-plugin.tsx +70 -0
  63. package/src/plugins/actions/counter-character-plugin.tsx +80 -0
  64. package/src/plugins/actions/edit-mode-toggle-plugin.tsx +49 -0
  65. package/src/plugins/actions/import-export-plugin.tsx +61 -0
  66. package/src/plugins/actions/markdown-toggle-plugin.tsx +78 -0
  67. package/src/plugins/actions/max-length-plugin.tsx +59 -0
  68. package/src/plugins/actions/share-content-plugin.tsx +72 -0
  69. package/src/plugins/actions/speech-to-text-plugin.tsx +159 -0
  70. package/src/plugins/actions/tree-view-plugin.tsx +63 -0
  71. package/src/plugins/align-plugin.tsx +86 -0
  72. package/src/plugins/auto-link-plugin.tsx +34 -0
  73. package/src/plugins/autocomplete-plugin.tsx +2574 -0
  74. package/src/plugins/code-action-menu-plugin.tsx +240 -0
  75. package/src/plugins/code-highlight-plugin.tsx +22 -0
  76. package/src/plugins/component-picker-menu-plugin.tsx +427 -0
  77. package/src/plugins/context-menu-plugin.tsx +311 -0
  78. package/src/plugins/drag-drop-paste-plugin.tsx +52 -0
  79. package/src/plugins/draggable-block-plugin.tsx +50 -0
  80. package/src/plugins/embeds/auto-embed-plugin.tsx +324 -0
  81. package/src/plugins/embeds/twitter-plugin.tsx +45 -0
  82. package/src/plugins/embeds/youtube-plugin.tsx +84 -0
  83. package/src/plugins/emoji-picker-plugin.tsx +206 -0
  84. package/src/plugins/emojis-plugin.tsx +84 -0
  85. package/src/plugins/floating-link-editor-plugin.tsx +791 -0
  86. package/src/plugins/floating-text-format-plugin.tsx +710 -0
  87. package/src/plugins/images-plugin.tsx +671 -0
  88. package/src/plugins/keywords-plugin.tsx +59 -0
  89. package/src/plugins/layout-plugin.tsx +658 -0
  90. package/src/plugins/link-plugin.tsx +18 -0
  91. package/src/plugins/list-color-plugin.tsx +178 -0
  92. package/src/plugins/list-max-indent-level-plugin.tsx +85 -0
  93. package/src/plugins/mentions-plugin.tsx +714 -0
  94. package/src/plugins/picker/alignment-picker-plugin.tsx +40 -0
  95. package/src/plugins/picker/bulleted-list-picker-plugin.tsx +14 -0
  96. package/src/plugins/picker/check-list-picker-plugin.tsx +14 -0
  97. package/src/plugins/picker/code-picker-plugin.tsx +30 -0
  98. package/src/plugins/picker/columns-layout-picker-plugin.tsx +16 -0
  99. package/src/plugins/picker/component-picker-option.tsx +47 -0
  100. package/src/plugins/picker/divider-picker-plugin.tsx +14 -0
  101. package/src/plugins/picker/embeds-picker-plugin.tsx +24 -0
  102. package/src/plugins/picker/heading-picker-plugin.tsx +32 -0
  103. package/src/plugins/picker/image-picker-plugin.tsx +16 -0
  104. package/src/plugins/picker/numbered-list-picker-plugin.tsx +14 -0
  105. package/src/plugins/picker/paragraph-picker-plugin.tsx +20 -0
  106. package/src/plugins/picker/quote-picker-plugin.tsx +21 -0
  107. package/src/plugins/picker/table-picker-plugin.tsx +56 -0
  108. package/src/plugins/tab-focus-plugin.tsx +66 -0
  109. package/src/plugins/table-column-resizer-plugin.tsx +309 -0
  110. package/src/plugins/table-plugin.tsx +299 -0
  111. package/src/plugins/toolbar/block-format/block-format-data.tsx +69 -0
  112. package/src/plugins/toolbar/block-format/format-bulleted-list.tsx +40 -0
  113. package/src/plugins/toolbar/block-format/format-check-list.tsx +40 -0
  114. package/src/plugins/toolbar/block-format/format-code-block.tsx +45 -0
  115. package/src/plugins/toolbar/block-format/format-heading.tsx +34 -0
  116. package/src/plugins/toolbar/block-format/format-list-with-marker.tsx +74 -0
  117. package/src/plugins/toolbar/block-format/format-numbered-list.tsx +40 -0
  118. package/src/plugins/toolbar/block-format/format-paragraph.tsx +31 -0
  119. package/src/plugins/toolbar/block-format/format-quote.tsx +32 -0
  120. package/src/plugins/toolbar/block-format-toolbar-plugin.tsx +117 -0
  121. package/src/plugins/toolbar/block-insert/insert-columns-layout.tsx +32 -0
  122. package/src/plugins/toolbar/block-insert/insert-embeds.tsx +31 -0
  123. package/src/plugins/toolbar/block-insert/insert-horizontal-rule.tsx +30 -0
  124. package/src/plugins/toolbar/block-insert/insert-image.tsx +32 -0
  125. package/src/plugins/toolbar/block-insert/insert-table.tsx +32 -0
  126. package/src/plugins/toolbar/block-insert-plugin.tsx +30 -0
  127. package/src/plugins/toolbar/clear-formatting-toolbar-plugin.tsx +92 -0
  128. package/src/plugins/toolbar/code-language-toolbar-plugin.tsx +121 -0
  129. package/src/plugins/toolbar/element-format-toolbar-plugin.tsx +251 -0
  130. package/src/plugins/toolbar/font-background-toolbar-plugin.tsx +179 -0
  131. package/src/plugins/toolbar/font-color-toolbar-plugin.tsx +101 -0
  132. package/src/plugins/toolbar/font-family-toolbar-plugin.tsx +91 -0
  133. package/src/plugins/toolbar/font-format-toolbar-plugin.tsx +85 -0
  134. package/src/plugins/toolbar/font-size-toolbar-plugin.tsx +177 -0
  135. package/src/plugins/toolbar/history-toolbar-plugin.tsx +87 -0
  136. package/src/plugins/toolbar/link-toolbar-plugin.tsx +90 -0
  137. package/src/plugins/toolbar/subsuper-toolbar-plugin.tsx +69 -0
  138. package/src/plugins/toolbar/toolbar-plugin.tsx +66 -0
  139. package/src/plugins/typing-pref-plugin.tsx +118 -0
  140. package/src/shared/can-use-dom.ts +4 -0
  141. package/src/shared/environment.ts +47 -0
  142. package/src/shared/invariant.ts +16 -0
  143. package/src/shared/use-layout-effect.ts +12 -0
  144. package/src/themes/_mixins.scss +107 -0
  145. package/src/themes/_variables.scss +33 -0
  146. package/src/themes/editor-theme.scss +622 -0
  147. package/src/themes/editor-theme.ts +118 -0
  148. package/src/themes/plugins.scss +1180 -0
  149. package/src/themes/ui-components.scss +936 -0
  150. package/src/transformers/markdown-emoji-transformer.ts +20 -0
  151. package/src/transformers/markdown-hr-transformer.ts +28 -0
  152. package/src/transformers/markdown-image-transformer.ts +31 -0
  153. package/src/transformers/markdown-list-transformer.ts +51 -0
  154. package/src/transformers/markdown-table-transformer.ts +200 -0
  155. package/src/transformers/markdown-tweet-transformer.ts +26 -0
  156. package/src/ui/button-group.tsx +10 -0
  157. package/src/ui/button.tsx +29 -0
  158. package/src/ui/collapsible.tsx +67 -0
  159. package/src/ui/command.tsx +48 -0
  160. package/src/ui/dialog.tsx +146 -0
  161. package/src/ui/flex.tsx +38 -0
  162. package/src/ui/input.tsx +20 -0
  163. package/src/ui/label.tsx +20 -0
  164. package/src/ui/popover.tsx +128 -0
  165. package/src/ui/scroll-area.tsx +17 -0
  166. package/src/ui/select.tsx +171 -0
  167. package/src/ui/separator.tsx +20 -0
  168. package/src/ui/slider.tsx +14 -0
  169. package/src/ui/slot.tsx +3 -0
  170. package/src/ui/tabs.tsx +87 -0
  171. package/src/ui/toggle-group.tsx +109 -0
  172. package/src/ui/toggle.tsx +28 -0
  173. package/src/ui/tooltip.tsx +28 -0
  174. package/src/ui/typography.tsx +44 -0
  175. package/src/utils/doc-serialization.ts +68 -0
  176. package/src/utils/emoji-list.ts +16604 -0
  177. package/src/utils/get-dom-range-rect.ts +20 -0
  178. package/src/utils/get-selected-node.ts +20 -0
  179. package/src/utils/is-mobile-width.ts +0 -0
  180. package/src/utils/set-floating-elem-position-for-link-editor.ts +39 -0
  181. package/src/utils/set-floating-elem-position.ts +44 -0
  182. package/src/utils/swipe.ts +119 -0
  183. package/src/utils/url.ts +32 -0
@@ -0,0 +1,321 @@
1
+ "use client"
2
+ import * as React from "react"
3
+ import {
4
+ JSX,
5
+ Suspense,
6
+ useCallback,
7
+ useEffect,
8
+ useRef,
9
+ useState,
10
+ } from "react"
11
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext"
12
+ import { useLexicalEditable } from "@lexical/react/useLexicalEditable"
13
+ import { $isNodeSelection, $getNodeByKey, NodeKey, LexicalEditor, FORMAT_ELEMENT_COMMAND, ElementFormatType } from "lexical"
14
+
15
+ import { ImageResizer } from "../editor-ui/image-resizer"
16
+ import { $isImageNode } from "../nodes/image-node"
17
+ import { cn } from "../lib/utils"
18
+ import { useEditorContainer } from "../context/editor-container-context"
19
+ import {
20
+ Dialog,
21
+ DialogContent,
22
+ DialogHeader,
23
+ DialogTitle,
24
+ } from "../ui/dialog"
25
+ import {
26
+ InsertImageDialog,
27
+ InsertImagePayload,
28
+ } from "../plugins/images-plugin"
29
+ import { usePriorityImage } from "../context/priority-image-context"
30
+
31
+ // Sub-components
32
+ import { LazyImage } from "./lazy-image"
33
+ import { BrokenImage } from "./broken-image"
34
+ import { ImagePlaceholder } from "./image-placeholder"
35
+ import { CaptionComposer } from "./caption-composer"
36
+
37
+ // Hooks
38
+ import { useResponsiveImageDimensions, DimensionValue } from "./hooks/use-responsive-image-dimensions"
39
+ import { useImageCaptionControls } from "./hooks/use-image-caption-controls"
40
+ import { useImageNodeInteractions } from "./hooks/use-image-node-interactions"
41
+
42
+ const RESIZE_HANDLE_HIDE_DELAY = 200
43
+
44
+ interface ImageComponentProps {
45
+ altText: string
46
+ caption: LexicalEditor
47
+ captionsEnabled: boolean
48
+ fullWidth: boolean
49
+ height: DimensionValue
50
+ maxWidth: number
51
+ nodeKey: NodeKey
52
+ resizable: boolean
53
+ showCaption: boolean
54
+ src: string
55
+ width: DimensionValue
56
+ }
57
+
58
+ /**
59
+ * ImageComponent - The main component for image nodes in the Lexical editor.
60
+ * Orchestrates image rendering, resizing, captions, and interactions.
61
+ */
62
+ export default function ImageComponent({
63
+ altText,
64
+ caption,
65
+ captionsEnabled,
66
+ fullWidth,
67
+ height,
68
+ maxWidth,
69
+ nodeKey,
70
+ resizable,
71
+ showCaption,
72
+ src,
73
+ width,
74
+ }: ImageComponentProps): JSX.Element {
75
+ const imageRef = useRef<null | HTMLImageElement>(null)
76
+ const buttonRef = useRef<HTMLButtonElement | null>(null)
77
+ const [isResizing, setIsResizing] = useState<boolean>(false)
78
+ const resizeTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
79
+ const [editor] = useLexicalComposerContext()
80
+ const [isLoadError, setIsLoadError] = useState<boolean>(false)
81
+ const [isReplaceDialogOpen, setIsReplaceDialogOpen] = useState(false)
82
+ const isEditable = useLexicalEditable()
83
+ const editorContainer = useEditorContainer()
84
+
85
+ const prioritySrc = usePriorityImage()
86
+ const isPriority = src === prioritySrc
87
+
88
+ // Custom hooks for logic separation
89
+ const {
90
+ hasCaptionContent,
91
+ localShowCaption,
92
+ setShowCaption,
93
+ } = useImageCaptionControls({
94
+ caption,
95
+ editor,
96
+ nodeKey,
97
+ showCaption,
98
+ })
99
+
100
+ const responsiveDimensions = useResponsiveImageDimensions({
101
+ editor,
102
+ imageRef,
103
+ width,
104
+ height,
105
+ isResizing,
106
+ fullWidth,
107
+ maxWidthLimit: editorContainer?.maxWidth,
108
+ src,
109
+ })
110
+
111
+ const { isSelected, selection } = useImageNodeInteractions({
112
+ buttonRef,
113
+ caption,
114
+ editor,
115
+ imageRef,
116
+ isResizing,
117
+ nodeKey,
118
+ showCaption,
119
+ })
120
+
121
+ useEffect(() => {
122
+ if (!isEditable && isReplaceDialogOpen) {
123
+ setTimeout(() => {
124
+ setIsReplaceDialogOpen(false)
125
+ }, 0)
126
+ }
127
+ }, [isEditable, isReplaceDialogOpen])
128
+
129
+ useEffect(() => {
130
+ return () => {
131
+ if (resizeTimeoutRef.current) {
132
+ clearTimeout(resizeTimeoutRef.current)
133
+ }
134
+ }
135
+ }, [])
136
+
137
+ const onResizeEnd = useCallback(
138
+ (nextWidth: DimensionValue, nextHeight: DimensionValue) => {
139
+ if (resizeTimeoutRef.current) {
140
+ clearTimeout(resizeTimeoutRef.current)
141
+ }
142
+ resizeTimeoutRef.current = setTimeout(() => {
143
+ setIsResizing(false)
144
+ }, RESIZE_HANDLE_HIDE_DELAY)
145
+
146
+ editor.update(() => {
147
+ const node = $getNodeByKey(nodeKey)
148
+ if ($isImageNode(node)) {
149
+ node.setWidthAndHeight(nextWidth, nextHeight)
150
+ }
151
+ })
152
+ },
153
+ [editor, nodeKey]
154
+ )
155
+
156
+ const onResizeStart = useCallback(() => {
157
+ setIsResizing(true)
158
+ editor.update(() => {
159
+ const node = $getNodeByKey(nodeKey)
160
+ if ($isImageNode(node)) {
161
+ node.setFullWidth(false)
162
+ }
163
+ })
164
+ }, [editor, nodeKey])
165
+
166
+ useEffect(() => {
167
+ const element = editor.getElementByKey(nodeKey)
168
+ if (element) {
169
+ if (fullWidth) {
170
+ element.style.width = "100%"
171
+ element.style.display = "block"
172
+ } else {
173
+ element.style.width = ""
174
+ element.style.display = "inline-block"
175
+ }
176
+ }
177
+ }, [editor, nodeKey, fullWidth])
178
+
179
+ const onSetFullWidth = useCallback(() => {
180
+ editor.update(() => {
181
+ const node = $getNodeByKey(nodeKey)
182
+ if ($isImageNode(node)) {
183
+ node.setFullWidth(!fullWidth)
184
+ }
185
+ })
186
+ }, [editor, fullWidth, nodeKey])
187
+
188
+ const onAlign = useCallback(
189
+ (format: ElementFormatType) => {
190
+ editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, format)
191
+ },
192
+ [editor]
193
+ )
194
+
195
+ const handleReplaceImage = useCallback(
196
+ (payload: InsertImagePayload) => {
197
+ if (!payload?.src) {
198
+ return
199
+ }
200
+ editor.update(() => {
201
+ const node = $getNodeByKey(nodeKey)
202
+ if ($isImageNode(node)) {
203
+ node.setSrc(payload.src)
204
+ if (payload.altText !== undefined) {
205
+ node.setAltText(payload.altText)
206
+ }
207
+ node.setWidthAndHeight("inherit", "inherit")
208
+ }
209
+ })
210
+ },
211
+ [editor, nodeKey]
212
+ )
213
+
214
+ const onDelete = useCallback(() => {
215
+ editor.update(() => {
216
+ const node = $getNodeByKey(nodeKey)
217
+ if ($isImageNode(node)) {
218
+ node.remove()
219
+ }
220
+ })
221
+ }, [editor, nodeKey])
222
+
223
+ const draggable = isSelected && $isNodeSelection(selection) && !isResizing
224
+ const isFocused = (isSelected || isResizing) && isEditable
225
+ const shouldRenderCaption =
226
+ showCaption &&
227
+ (isEditable
228
+ ? localShowCaption && captionsEnabled
229
+ : hasCaptionContent)
230
+
231
+ const imageClassName = cn(
232
+ "editor-image",
233
+ isFocused && "editor-image-focused",
234
+ isFocused && $isNodeSelection(selection) && "editor-image-draggable",
235
+ fullWidth && "full-width"
236
+ )
237
+
238
+ const captionWrapperClass = cn(
239
+ "editor-image-caption",
240
+ isEditable ? "editable" : "readonly"
241
+ )
242
+
243
+ return (
244
+ <Suspense
245
+ fallback={
246
+ <div draggable={draggable}>
247
+ <ImagePlaceholder
248
+ width={responsiveDimensions.width}
249
+ height={responsiveDimensions.height}
250
+ />
251
+ </div>
252
+ }
253
+ >
254
+ <>
255
+ <div draggable={draggable} style={{ display: "inline-block" }}>
256
+ {isLoadError ? (
257
+ <BrokenImage />
258
+ ) : (
259
+ <LazyImage
260
+ className={imageClassName}
261
+ src={src}
262
+ altText={altText}
263
+ imageRef={imageRef}
264
+ width={responsiveDimensions.width}
265
+ height={responsiveDimensions.height}
266
+ maxWidth={maxWidth}
267
+ onError={() => setIsLoadError(true)}
268
+ fetchPriority={isPriority ? "high" : "auto"}
269
+ />
270
+ )}
271
+ </div>
272
+
273
+ {shouldRenderCaption && (
274
+ <div className={captionWrapperClass}>
275
+ <CaptionComposer caption={caption} isEditable={isEditable} />
276
+ </div>
277
+ )}
278
+
279
+ {resizable && isFocused && (
280
+ <ImageResizer
281
+ buttonRef={buttonRef}
282
+ showCaption={showCaption}
283
+ setShowCaption={setShowCaption}
284
+ editor={editor}
285
+ mediaRef={imageRef}
286
+ onResizeStart={onResizeStart}
287
+ onResizeEnd={onResizeEnd}
288
+ captionsEnabled={captionsEnabled}
289
+ onReplaceMedia={() => setIsReplaceDialogOpen(true)}
290
+ onSetFullWidth={onSetFullWidth}
291
+ isFullWidth={fullWidth}
292
+ onDelete={onDelete}
293
+ onAlign={onAlign}
294
+ />
295
+ )}
296
+
297
+ {isEditable && isReplaceDialogOpen && (
298
+ <Dialog
299
+ open={isReplaceDialogOpen}
300
+ onOpenChange={setIsReplaceDialogOpen}
301
+ >
302
+ <DialogContent className="editor-dialog-content--lg" disableOutsideClick={true}>
303
+ <DialogHeader>
304
+ <DialogTitle>Thay thế hình ảnh</DialogTitle>
305
+ </DialogHeader>
306
+ <InsertImageDialog
307
+ activeEditor={editor}
308
+ activeTab="url"
309
+ onClose={() => setIsReplaceDialogOpen(false)}
310
+ onInsert={(payload) => {
311
+ handleReplaceImage(payload)
312
+ setIsReplaceDialogOpen(false)
313
+ }}
314
+ />
315
+ </DialogContent>
316
+ </Dialog>
317
+ )}
318
+ </>
319
+ </Suspense>
320
+ )
321
+ }
@@ -0,0 +1,57 @@
1
+ import * as React from "react"
2
+ import { JSX } from "react"
3
+ import { DimensionValue } from "./hooks/use-responsive-image-dimensions"
4
+
5
+ interface ImagePlaceholderProps {
6
+ width: DimensionValue
7
+ height: DimensionValue
8
+ }
9
+
10
+ /**
11
+ * ImagePlaceholder - Rendered while an image is loading or when dimensions are being calculated.
12
+ */
13
+ export function ImagePlaceholder({
14
+ width,
15
+ height,
16
+ }: ImagePlaceholderProps): JSX.Element {
17
+ const MAX_CONTAINER_WIDTH = 800
18
+ const MAX_CONTAINER_HEIGHT = 600
19
+
20
+ const getNumeric = (val: DimensionValue, max: number) => {
21
+ if (typeof val === "number") return val
22
+ return max
23
+ }
24
+
25
+ const pWidth = getNumeric(width, MAX_CONTAINER_WIDTH)
26
+ const pHeight = getNumeric(height, MAX_CONTAINER_HEIGHT)
27
+
28
+ return (
29
+ <div
30
+ className="editor-article-image-placeholder editor-animate-pulse editor-bg-muted editor-flex editor-items-center editor-justify-center editor-rounded-lg"
31
+ style={{
32
+ width: width === "inherit" ? "100%" : pWidth,
33
+ height: height === "inherit" ? "auto" : pHeight,
34
+ aspectRatio: width === "inherit" || height === "inherit" ? "16/9" : undefined,
35
+ maxWidth: "100%",
36
+ }}
37
+ >
38
+ <div className="editor-flex editor-flex-col editor-items-center editor-gap-2 editor-text-muted-foreground">
39
+ <svg
40
+ xmlns="http://www.w3.org/2000/svg"
41
+ width="40"
42
+ height="40"
43
+ viewBox="0 0 24 24"
44
+ fill="none"
45
+ stroke="currentColor"
46
+ strokeWidth="2"
47
+ strokeLinecap="round"
48
+ strokeLinejoin="round"
49
+ >
50
+ <rect width="18" height="18" x="3" y="3" rx="2" ry="2" />
51
+ <circle cx="9" cy="9" r="2" />
52
+ <path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" />
53
+ </svg>
54
+ </div>
55
+ </div>
56
+ )
57
+ }