@webiny/lexical-nodes 5.38.0-beta.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.
Files changed (72) hide show
  1. package/FontColorNode.d.ts +43 -0
  2. package/FontColorNode.js +125 -0
  3. package/FontColorNode.js.map +1 -0
  4. package/HeadingNode.d.ts +32 -0
  5. package/HeadingNode.js +193 -0
  6. package/HeadingNode.js.map +1 -0
  7. package/ImageNode.d.ts +58 -0
  8. package/ImageNode.js +217 -0
  9. package/ImageNode.js.map +1 -0
  10. package/LICENSE +21 -0
  11. package/LinkNode.d.ts +106 -0
  12. package/LinkNode.js +531 -0
  13. package/LinkNode.js.map +1 -0
  14. package/ListItemNode.d.ts +44 -0
  15. package/ListItemNode.js +442 -0
  16. package/ListItemNode.js.map +1 -0
  17. package/ListNode.d.ts +42 -0
  18. package/ListNode.js +290 -0
  19. package/ListNode.js.map +1 -0
  20. package/ParagraphNode.d.ts +31 -0
  21. package/ParagraphNode.js +220 -0
  22. package/ParagraphNode.js.map +1 -0
  23. package/QuoteNode.d.ts +33 -0
  24. package/QuoteNode.js +227 -0
  25. package/QuoteNode.js.map +1 -0
  26. package/README.md +6 -0
  27. package/TypographyNode.d.ts +41 -0
  28. package/TypographyNode.js +153 -0
  29. package/TypographyNode.js.map +1 -0
  30. package/components/ImageNode/ContentEditable.css +22 -0
  31. package/components/ImageNode/ContentEditable.d.ts +12 -0
  32. package/components/ImageNode/ContentEditable.js +26 -0
  33. package/components/ImageNode/ContentEditable.js.map +1 -0
  34. package/components/ImageNode/ImageComponent.css +43 -0
  35. package/components/ImageNode/ImageComponent.d.ts +16 -0
  36. package/components/ImageNode/ImageComponent.js +254 -0
  37. package/components/ImageNode/ImageComponent.js.map +1 -0
  38. package/components/ImageNode/ImageResizer.d.ts +26 -0
  39. package/components/ImageNode/ImageResizer.js +215 -0
  40. package/components/ImageNode/ImageResizer.js.map +1 -0
  41. package/components/ImageNode/Placeholder.css +20 -0
  42. package/components/ImageNode/Placeholder.d.ts +15 -0
  43. package/components/ImageNode/Placeholder.js +30 -0
  44. package/components/ImageNode/Placeholder.js.map +1 -0
  45. package/components/ImageNode/SharedHistoryContext.d.ts +11 -0
  46. package/components/ImageNode/SharedHistoryContext.js +28 -0
  47. package/components/ImageNode/SharedHistoryContext.js.map +1 -0
  48. package/index.d.ts +22 -0
  49. package/index.js +226 -0
  50. package/index.js.map +1 -0
  51. package/package.json +32 -0
  52. package/types.d.ts +15 -0
  53. package/types.js +7 -0
  54. package/types.js.map +1 -0
  55. package/utils/clearNodeFormating.d.ts +2 -0
  56. package/utils/clearNodeFormating.js +30 -0
  57. package/utils/clearNodeFormating.js.map +1 -0
  58. package/utils/formatList.d.ts +19 -0
  59. package/utils/formatList.js +449 -0
  60. package/utils/formatList.js.map +1 -0
  61. package/utils/formatToHeading.d.ts +3 -0
  62. package/utils/formatToHeading.js +27 -0
  63. package/utils/formatToHeading.js.map +1 -0
  64. package/utils/formatToParagraph.d.ts +2 -0
  65. package/utils/formatToParagraph.js +22 -0
  66. package/utils/formatToParagraph.js.map +1 -0
  67. package/utils/formatToQuote.d.ts +2 -0
  68. package/utils/formatToQuote.js +27 -0
  69. package/utils/formatToQuote.js.map +1 -0
  70. package/utils/listNode.d.ts +11 -0
  71. package/utils/listNode.js +109 -0
  72. package/utils/listNode.js.map +1 -0
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = ImageComponent;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var React = _interopRequireWildcard(require("react"));
11
+ require("./ImageComponent.css");
12
+ var _LexicalAutoFocusPlugin = require("@lexical/react/LexicalAutoFocusPlugin");
13
+ var _LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
14
+ var _LexicalErrorBoundary = _interopRequireDefault(require("@lexical/react/LexicalErrorBoundary"));
15
+ var _LexicalHistoryPlugin = require("@lexical/react/LexicalHistoryPlugin");
16
+ var _LexicalNestedComposer = require("@lexical/react/LexicalNestedComposer");
17
+ var _LexicalRichTextPlugin = require("@lexical/react/LexicalRichTextPlugin");
18
+ var _useLexicalNodeSelection = require("@lexical/react/useLexicalNodeSelection");
19
+ var _utils = require("@lexical/utils");
20
+ var _lexical = require("lexical");
21
+ var _Placeholder = require("./Placeholder");
22
+ var _ImageResizer = require("./ImageResizer");
23
+ var _SharedHistoryContext = require("./SharedHistoryContext");
24
+ var _ImageNode = require("../../ImageNode");
25
+ var _ContentEditable = require("./ContentEditable");
26
+ /**
27
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
28
+ *
29
+ * This source code is licensed under the MIT license found in the
30
+ * LICENSE file in the root directory of this source tree.
31
+ *
32
+ */
33
+
34
+ var imageCache = new Set();
35
+ function useSuspenseImage(src) {
36
+ if (!imageCache.has(src)) {
37
+ throw new Promise(function (resolve) {
38
+ var img = new Image();
39
+ img.src = src;
40
+ img.onload = function () {
41
+ imageCache.add(src);
42
+ resolve(null);
43
+ };
44
+ });
45
+ }
46
+ }
47
+ function LazyImage(_ref) {
48
+ var id = _ref.id,
49
+ altText = _ref.altText,
50
+ className = _ref.className,
51
+ imageRef = _ref.imageRef,
52
+ src = _ref.src,
53
+ width = _ref.width,
54
+ height = _ref.height,
55
+ maxWidth = _ref.maxWidth;
56
+ useSuspenseImage(src);
57
+ return /*#__PURE__*/React.createElement("img", {
58
+ id: id,
59
+ className: className || undefined,
60
+ src: src,
61
+ alt: altText,
62
+ ref: imageRef,
63
+ style: {
64
+ height: height,
65
+ maxWidth: maxWidth,
66
+ width: width
67
+ },
68
+ draggable: "false"
69
+ });
70
+ }
71
+ function ImageComponent(_ref2) {
72
+ var id = _ref2.id,
73
+ src = _ref2.src,
74
+ altText = _ref2.altText,
75
+ nodeKey = _ref2.nodeKey,
76
+ width = _ref2.width,
77
+ height = _ref2.height,
78
+ maxWidth = _ref2.maxWidth,
79
+ resizable = _ref2.resizable,
80
+ showCaption = _ref2.showCaption,
81
+ caption = _ref2.caption,
82
+ captionsEnabled = _ref2.captionsEnabled;
83
+ var imageRef = (0, React.useRef)(null);
84
+ var buttonRef = (0, React.useRef)(null);
85
+ var _useLexicalNodeSelect = (0, _useLexicalNodeSelection.useLexicalNodeSelection)(nodeKey),
86
+ _useLexicalNodeSelect2 = (0, _slicedToArray2.default)(_useLexicalNodeSelect, 3),
87
+ isSelected = _useLexicalNodeSelect2[0],
88
+ setSelected = _useLexicalNodeSelect2[1],
89
+ clearSelection = _useLexicalNodeSelect2[2];
90
+ var _useState = (0, React.useState)(false),
91
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
92
+ isResizing = _useState2[0],
93
+ setIsResizing = _useState2[1];
94
+ var _useLexicalComposerCo = (0, _LexicalComposerContext.useLexicalComposerContext)(),
95
+ _useLexicalComposerCo2 = (0, _slicedToArray2.default)(_useLexicalComposerCo, 1),
96
+ editor = _useLexicalComposerCo2[0];
97
+ var _useState3 = (0, React.useState)(null),
98
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
99
+ selection = _useState4[0],
100
+ setSelection = _useState4[1];
101
+ var activeEditorRef = (0, React.useRef)(null);
102
+ var onDelete = (0, React.useCallback)(function (payload) {
103
+ if (isSelected && (0, _lexical.$isNodeSelection)((0, _lexical.$getSelection)())) {
104
+ var event = payload;
105
+ event.preventDefault();
106
+ var node = (0, _lexical.$getNodeByKey)(nodeKey);
107
+ if ((0, _ImageNode.$isImageNode)(node)) {
108
+ node.remove();
109
+ }
110
+ setSelected(false);
111
+ }
112
+ return false;
113
+ }, [isSelected, nodeKey, setSelected]);
114
+ var onEnter = (0, React.useCallback)(function (event) {
115
+ var latestSelection = (0, _lexical.$getSelection)();
116
+ var buttonElem = buttonRef.current;
117
+ if (isSelected && (0, _lexical.$isNodeSelection)(latestSelection) && latestSelection.getNodes().length === 1) {
118
+ if (showCaption) {
119
+ // Move focus into nested editor
120
+ (0, _lexical.$setSelection)(null);
121
+ event.preventDefault();
122
+ caption.focus();
123
+ return true;
124
+ } else if (buttonElem !== null && buttonElem !== document.activeElement) {
125
+ event.preventDefault();
126
+ buttonElem.focus();
127
+ return true;
128
+ }
129
+ }
130
+ return false;
131
+ }, [caption, isSelected, showCaption]);
132
+ var onEscape = (0, React.useCallback)(function (event) {
133
+ if (activeEditorRef.current === caption || buttonRef.current === event.target) {
134
+ (0, _lexical.$setSelection)(null);
135
+ editor.update(function () {
136
+ setSelected(true);
137
+ var parentRootElement = editor.getRootElement();
138
+ if (parentRootElement !== null) {
139
+ parentRootElement.focus();
140
+ }
141
+ });
142
+ return true;
143
+ }
144
+ return false;
145
+ }, [caption, editor, setSelected]);
146
+ (0, React.useEffect)(function () {
147
+ var isMounted = true;
148
+ var unregister = (0, _utils.mergeRegister)(editor.registerUpdateListener(function (_ref3) {
149
+ var editorState = _ref3.editorState;
150
+ if (isMounted) {
151
+ setSelection(editorState.read(function () {
152
+ return (0, _lexical.$getSelection)();
153
+ }));
154
+ }
155
+ }), editor.registerCommand(_lexical.SELECTION_CHANGE_COMMAND, function (_, activeEditor) {
156
+ activeEditorRef.current = activeEditor;
157
+ return false;
158
+ }, _lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(_lexical.CLICK_COMMAND, function (payload) {
159
+ var event = payload;
160
+ if (isResizing) {
161
+ return true;
162
+ }
163
+ if (event.target === imageRef.current) {
164
+ if (event.shiftKey) {
165
+ setSelected(!isSelected);
166
+ } else {
167
+ clearSelection();
168
+ setSelected(true);
169
+ }
170
+ return true;
171
+ }
172
+ return false;
173
+ }, _lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(_lexical.DRAGSTART_COMMAND, function (event) {
174
+ if (event.target === imageRef.current) {
175
+ // TODO This is just a temporary workaround for FF to behave like other browsers.
176
+ // Ideally, this handles drag & drop too (and all browsers).
177
+ event.preventDefault();
178
+ return true;
179
+ }
180
+ return false;
181
+ }, _lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(_lexical.KEY_DELETE_COMMAND, onDelete, _lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(_lexical.KEY_BACKSPACE_COMMAND, onDelete, _lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(_lexical.KEY_ENTER_COMMAND, onEnter, _lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(_lexical.KEY_ESCAPE_COMMAND, onEscape, _lexical.COMMAND_PRIORITY_LOW));
182
+ return function () {
183
+ isMounted = false;
184
+ unregister();
185
+ };
186
+ }, [clearSelection, editor, isResizing, isSelected, nodeKey, onDelete, onEnter, onEscape, setSelected]);
187
+ var setShowCaption = function setShowCaption() {
188
+ editor.update(function () {
189
+ var node = (0, _lexical.$getNodeByKey)(nodeKey);
190
+ if ((0, _ImageNode.$isImageNode)(node)) {
191
+ node.setShowCaption(true);
192
+ }
193
+ });
194
+ };
195
+ var onResizeEnd = function onResizeEnd(nextWidth, nextHeight) {
196
+ // Delay hiding the resize bars for click case
197
+ setTimeout(function () {
198
+ setIsResizing(false);
199
+ }, 200);
200
+ editor.update(function () {
201
+ var node = (0, _lexical.$getNodeByKey)(nodeKey);
202
+ if ((0, _ImageNode.$isImageNode)(node)) {
203
+ node.setWidthAndHeight(nextWidth, nextHeight);
204
+ }
205
+ });
206
+ };
207
+ var onResizeStart = function onResizeStart() {
208
+ setIsResizing(true);
209
+ };
210
+ var _useSharedHistoryCont = (0, _SharedHistoryContext.useSharedHistoryContext)(),
211
+ historyState = _useSharedHistoryCont.historyState;
212
+ var draggable = isSelected && (0, _lexical.$isNodeSelection)(selection) && !isResizing;
213
+ var isFocused = isSelected || isResizing;
214
+ return /*#__PURE__*/React.createElement(React.Suspense, {
215
+ fallback: null
216
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
217
+ draggable: draggable
218
+ }, /*#__PURE__*/React.createElement(LazyImage, {
219
+ id: id,
220
+ className: isFocused ? "focused ".concat((0, _lexical.$isNodeSelection)(selection) ? "draggable" : "") : null,
221
+ src: src,
222
+ altText: altText,
223
+ imageRef: imageRef,
224
+ width: width,
225
+ height: height,
226
+ maxWidth: maxWidth
227
+ })), showCaption && /*#__PURE__*/React.createElement("div", {
228
+ className: "image-caption-container"
229
+ }, /*#__PURE__*/React.createElement(_LexicalNestedComposer.LexicalNestedComposer, {
230
+ initialEditor: caption
231
+ }, /*#__PURE__*/React.createElement(_LexicalAutoFocusPlugin.AutoFocusPlugin, null), /*#__PURE__*/React.createElement(_LexicalHistoryPlugin.HistoryPlugin, {
232
+ externalHistoryState: historyState
233
+ }), /*#__PURE__*/React.createElement(_LexicalRichTextPlugin.RichTextPlugin, {
234
+ contentEditable: /*#__PURE__*/React.createElement(_ContentEditable.LexicalContentEditable, {
235
+ className: "ImageNode__contentEditable"
236
+ }),
237
+ placeholder: /*#__PURE__*/React.createElement(_Placeholder.Placeholder, {
238
+ className: "ImageNode__placeholder"
239
+ }, "Enter a caption..."),
240
+ ErrorBoundary: _LexicalErrorBoundary.default
241
+ }))), resizable && (0, _lexical.$isNodeSelection)(selection) && isFocused && /*#__PURE__*/React.createElement(_ImageResizer.ImageResizer, {
242
+ showCaption: showCaption,
243
+ setShowCaption: setShowCaption,
244
+ editor: editor,
245
+ buttonRef: buttonRef,
246
+ imageRef: imageRef,
247
+ maxWidth: maxWidth,
248
+ onResizeStart: onResizeStart,
249
+ onResizeEnd: onResizeEnd,
250
+ captionsEnabled: captionsEnabled
251
+ })));
252
+ }
253
+
254
+ //# sourceMappingURL=ImageComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","_interopRequireWildcard","require","_LexicalAutoFocusPlugin","_LexicalComposerContext","_LexicalErrorBoundary","_interopRequireDefault","_LexicalHistoryPlugin","_LexicalNestedComposer","_LexicalRichTextPlugin","_useLexicalNodeSelection","_utils","_lexical","_Placeholder","_ImageResizer","_SharedHistoryContext","_ImageNode","_ContentEditable","imageCache","Set","useSuspenseImage","src","has","Promise","resolve","img","Image","onload","add","LazyImage","_ref","id","altText","className","imageRef","width","height","maxWidth","createElement","undefined","alt","ref","style","draggable","ImageComponent","_ref2","nodeKey","resizable","showCaption","caption","captionsEnabled","useRef","buttonRef","_useLexicalNodeSelect","useLexicalNodeSelection","_useLexicalNodeSelect2","_slicedToArray2","default","isSelected","setSelected","clearSelection","_useState","useState","_useState2","isResizing","setIsResizing","_useLexicalComposerCo","useLexicalComposerContext","_useLexicalComposerCo2","editor","_useState3","_useState4","selection","setSelection","activeEditorRef","onDelete","useCallback","payload","$isNodeSelection","$getSelection","event","preventDefault","node","$getNodeByKey","$isImageNode","remove","onEnter","latestSelection","buttonElem","current","getNodes","length","$setSelection","focus","document","activeElement","onEscape","target","update","parentRootElement","getRootElement","useEffect","isMounted","unregister","mergeRegister","registerUpdateListener","_ref3","editorState","read","registerCommand","SELECTION_CHANGE_COMMAND","_","activeEditor","COMMAND_PRIORITY_LOW","CLICK_COMMAND","shiftKey","DRAGSTART_COMMAND","KEY_DELETE_COMMAND","KEY_BACKSPACE_COMMAND","KEY_ENTER_COMMAND","KEY_ESCAPE_COMMAND","setShowCaption","onResizeEnd","nextWidth","nextHeight","setTimeout","setWidthAndHeight","onResizeStart","_useSharedHistoryCont","useSharedHistoryContext","historyState","isFocused","Suspense","fallback","Fragment","concat","LexicalNestedComposer","initialEditor","AutoFocusPlugin","HistoryPlugin","externalHistoryState","RichTextPlugin","contentEditable","LexicalContentEditable","placeholder","Placeholder","ErrorBoundary","LexicalErrorBoundary","ImageResizer"],"sources":["ImageComponent.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport * as React from \"react\";\nimport { Suspense, useCallback, useEffect, useRef, useState } from \"react\";\n\nimport type { GridSelection, LexicalEditor, NodeKey, NodeSelection, RangeSelection } from \"lexical\";\n\nimport \"./ImageComponent.css\";\n\nimport { AutoFocusPlugin } from \"@lexical/react/LexicalAutoFocusPlugin\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport LexicalErrorBoundary from \"@lexical/react/LexicalErrorBoundary\";\nimport { HistoryPlugin } from \"@lexical/react/LexicalHistoryPlugin\";\nimport { LexicalNestedComposer } from \"@lexical/react/LexicalNestedComposer\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport { useLexicalNodeSelection } from \"@lexical/react/useLexicalNodeSelection\";\nimport { mergeRegister } from \"@lexical/utils\";\nimport {\n $getNodeByKey,\n $getSelection,\n $isNodeSelection,\n $setSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_LOW,\n DRAGSTART_COMMAND,\n KEY_BACKSPACE_COMMAND,\n KEY_DELETE_COMMAND,\n KEY_ENTER_COMMAND,\n KEY_ESCAPE_COMMAND,\n SELECTION_CHANGE_COMMAND\n} from \"lexical\";\nimport { Placeholder } from \"./Placeholder\";\nimport { ImageResizer } from \"./ImageResizer\";\nimport { useSharedHistoryContext } from \"./SharedHistoryContext\";\nimport { $isImageNode } from \"~/ImageNode\";\nimport { LexicalContentEditable } from \"./ContentEditable\";\n\nconst imageCache = new Set();\n\nfunction useSuspenseImage(src: string) {\n if (!imageCache.has(src)) {\n throw new Promise(resolve => {\n const img = new Image();\n img.src = src;\n img.onload = () => {\n imageCache.add(src);\n resolve(null);\n };\n });\n }\n}\n\nfunction LazyImage({\n id,\n altText,\n className,\n imageRef,\n src,\n width,\n height,\n maxWidth\n}: {\n id: string;\n altText: string;\n className: string | null;\n height: \"inherit\" | number;\n imageRef: { current: null | HTMLImageElement };\n maxWidth: number;\n src: string;\n width: \"inherit\" | number;\n}): JSX.Element {\n useSuspenseImage(src);\n return (\n <img\n id={id}\n className={className || undefined}\n src={src}\n alt={altText}\n ref={imageRef}\n style={{\n height,\n maxWidth,\n width\n }}\n draggable=\"false\"\n />\n );\n}\n\nexport default function ImageComponent({\n id,\n src,\n altText,\n nodeKey,\n width,\n height,\n maxWidth,\n resizable,\n showCaption,\n caption,\n captionsEnabled\n}: {\n id: string;\n altText: string;\n caption: LexicalEditor;\n height: \"inherit\" | number;\n maxWidth: number;\n nodeKey: NodeKey;\n resizable: boolean;\n showCaption: boolean;\n src: string;\n width: \"inherit\" | number;\n captionsEnabled: boolean;\n}): JSX.Element {\n const imageRef = useRef<null | HTMLImageElement>(null);\n const buttonRef = useRef<HTMLButtonElement | null>(null);\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);\n const [isResizing, setIsResizing] = useState<boolean>(false);\n const [editor] = useLexicalComposerContext();\n const [selection, setSelection] = useState<\n RangeSelection | NodeSelection | GridSelection | null\n >(null);\n const activeEditorRef = useRef<LexicalEditor | null>(null);\n\n const onDelete = useCallback(\n (payload: KeyboardEvent) => {\n if (isSelected && $isNodeSelection($getSelection())) {\n const event: KeyboardEvent = payload;\n event.preventDefault();\n const node = $getNodeByKey(nodeKey);\n if ($isImageNode(node)) {\n node.remove();\n }\n setSelected(false);\n }\n return false;\n },\n [isSelected, nodeKey, setSelected]\n );\n\n const onEnter = useCallback(\n (event: KeyboardEvent) => {\n const latestSelection = $getSelection();\n const buttonElem = buttonRef.current;\n if (\n isSelected &&\n $isNodeSelection(latestSelection) &&\n latestSelection.getNodes().length === 1\n ) {\n if (showCaption) {\n // Move focus into nested editor\n $setSelection(null);\n event.preventDefault();\n caption.focus();\n return true;\n } else if (buttonElem !== null && buttonElem !== document.activeElement) {\n event.preventDefault();\n buttonElem.focus();\n return true;\n }\n }\n return false;\n },\n [caption, isSelected, showCaption]\n );\n\n const onEscape = useCallback(\n (event: KeyboardEvent) => {\n if (activeEditorRef.current === caption || buttonRef.current === event.target) {\n $setSelection(null);\n editor.update(() => {\n setSelected(true);\n const parentRootElement = editor.getRootElement();\n if (parentRootElement !== null) {\n parentRootElement.focus();\n }\n });\n return true;\n }\n return false;\n },\n [caption, editor, setSelected]\n );\n\n useEffect(() => {\n let isMounted = true;\n const unregister = mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n if (isMounted) {\n setSelection(editorState.read(() => $getSelection()));\n }\n }),\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n (_, activeEditor) => {\n activeEditorRef.current = activeEditor;\n return false;\n },\n COMMAND_PRIORITY_LOW\n ),\n editor.registerCommand<MouseEvent>(\n CLICK_COMMAND,\n payload => {\n const event = payload;\n if (isResizing) {\n return true;\n }\n if (event.target === imageRef.current) {\n if (event.shiftKey) {\n setSelected(!isSelected);\n } else {\n clearSelection();\n setSelected(true);\n }\n return true;\n }\n\n return false;\n },\n COMMAND_PRIORITY_LOW\n ),\n editor.registerCommand(\n DRAGSTART_COMMAND,\n event => {\n if (event.target === imageRef.current) {\n // TODO This is just a temporary workaround for FF to behave like other browsers.\n // Ideally, this handles drag & drop too (and all browsers).\n event.preventDefault();\n return true;\n }\n return false;\n },\n COMMAND_PRIORITY_LOW\n ),\n editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_ENTER_COMMAND, onEnter, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_ESCAPE_COMMAND, onEscape, COMMAND_PRIORITY_LOW)\n );\n return () => {\n isMounted = false;\n unregister();\n };\n }, [\n clearSelection,\n editor,\n isResizing,\n isSelected,\n nodeKey,\n onDelete,\n onEnter,\n onEscape,\n setSelected\n ]);\n\n const setShowCaption = () => {\n editor.update(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isImageNode(node)) {\n node.setShowCaption(true);\n }\n });\n };\n\n const onResizeEnd = (nextWidth: \"inherit\" | number, nextHeight: \"inherit\" | number) => {\n // Delay hiding the resize bars for click case\n setTimeout(() => {\n setIsResizing(false);\n }, 200);\n\n editor.update(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isImageNode(node)) {\n node.setWidthAndHeight(nextWidth, nextHeight);\n }\n });\n };\n\n const onResizeStart = () => {\n setIsResizing(true);\n };\n\n const { historyState } = useSharedHistoryContext();\n const draggable = isSelected && $isNodeSelection(selection) && !isResizing;\n const isFocused = isSelected || isResizing;\n return (\n <Suspense fallback={null}>\n <>\n <div draggable={draggable}>\n <LazyImage\n id={id}\n className={\n isFocused\n ? `focused ${$isNodeSelection(selection) ? \"draggable\" : \"\"}`\n : null\n }\n src={src}\n altText={altText}\n imageRef={imageRef}\n width={width}\n height={height}\n maxWidth={maxWidth}\n />\n </div>\n {showCaption && (\n <div className=\"image-caption-container\">\n <LexicalNestedComposer initialEditor={caption}>\n <AutoFocusPlugin />\n <HistoryPlugin externalHistoryState={historyState} />\n <RichTextPlugin\n contentEditable={\n <LexicalContentEditable className=\"ImageNode__contentEditable\" />\n }\n placeholder={\n <Placeholder className=\"ImageNode__placeholder\">\n Enter a caption...\n </Placeholder>\n }\n ErrorBoundary={LexicalErrorBoundary}\n />\n </LexicalNestedComposer>\n </div>\n )}\n {resizable && $isNodeSelection(selection) && isFocused && (\n <ImageResizer\n showCaption={showCaption}\n setShowCaption={setShowCaption}\n editor={editor}\n buttonRef={buttonRef}\n imageRef={imageRef}\n maxWidth={maxWidth}\n onResizeStart={onResizeStart}\n onResizeEnd={onResizeEnd}\n captionsEnabled={captionsEnabled}\n />\n )}\n </>\n </Suspense>\n );\n}\n"],"mappings":";;;;;;;;;AAOA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAKAA,OAAA;AAEA,IAAAC,uBAAA,GAAAD,OAAA;AACA,IAAAE,uBAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,qBAAA,GAAAL,OAAA;AACA,IAAAM,sBAAA,GAAAN,OAAA;AACA,IAAAO,sBAAA,GAAAP,OAAA;AACA,IAAAQ,wBAAA,GAAAR,OAAA;AACA,IA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2D,SAAS,iBAClDnI,KAAA,CAAAsC,aAAA,CAACxB,aAAA,CAAAsI,YAAY;IACTpG,WAAW,EAAEA,WAAY;IACzByE,cAAc,EAAEA,cAAe;IAC/BpD,MAAM,EAAEA,MAAO;IACfjB,SAAS,EAAEA,SAAU;IACrBlB,QAAQ,EAAEA,QAAS;IACnBG,QAAQ,EAAEA,QAAS;IACnB0F,aAAa,EAAEA,aAAc;IAC7BL,WAAW,EAAEA,WAAY;IACzBxE,eAAe,EAAEA;EAAgB,CACpC,CAEP,CACI,CAAC;AAEnB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ /// <reference types="react" />
9
+ /// <reference types="web" />
10
+ /// <reference types="react" />
11
+ import type { LexicalEditor } from "lexical";
12
+ export declare function ImageResizer({ onResizeStart, onResizeEnd, buttonRef, imageRef, maxWidth, editor, showCaption, setShowCaption, captionsEnabled }: {
13
+ editor: LexicalEditor;
14
+ buttonRef: {
15
+ current: null | HTMLButtonElement;
16
+ };
17
+ imageRef: {
18
+ current: null | HTMLElement;
19
+ };
20
+ maxWidth?: number;
21
+ onResizeEnd: (width: "inherit" | number, height: "inherit" | number) => void;
22
+ onResizeStart: () => void;
23
+ setShowCaption: (show: boolean) => void;
24
+ showCaption: boolean;
25
+ captionsEnabled: boolean;
26
+ }): JSX.Element;
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ImageResizer = ImageResizer;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ /**
10
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ *
15
+ */
16
+
17
+ function clamp(value, min, max) {
18
+ return Math.min(Math.max(value, min), max);
19
+ }
20
+ var Direction = {
21
+ east: 1 << 0,
22
+ north: 1 << 3,
23
+ south: 1 << 1,
24
+ west: 1 << 2
25
+ };
26
+ function ImageResizer(_ref) {
27
+ var onResizeStart = _ref.onResizeStart,
28
+ onResizeEnd = _ref.onResizeEnd,
29
+ buttonRef = _ref.buttonRef,
30
+ imageRef = _ref.imageRef,
31
+ maxWidth = _ref.maxWidth,
32
+ editor = _ref.editor,
33
+ showCaption = _ref.showCaption,
34
+ setShowCaption = _ref.setShowCaption,
35
+ captionsEnabled = _ref.captionsEnabled;
36
+ var controlWrapperRef = (0, React.useRef)(null);
37
+ var userSelect = (0, React.useRef)({
38
+ priority: "",
39
+ value: "default"
40
+ });
41
+ var positioningRef = (0, React.useRef)({
42
+ currentHeight: 0,
43
+ currentWidth: 0,
44
+ direction: 0,
45
+ isResizing: false,
46
+ ratio: 0,
47
+ startHeight: 0,
48
+ startWidth: 0,
49
+ startX: 0,
50
+ startY: 0
51
+ });
52
+ var editorRootElement = editor.getRootElement();
53
+ // Find max width, accounting for editor padding.
54
+ var maxWidthContainer = maxWidth ? maxWidth : editorRootElement !== null ? editorRootElement.getBoundingClientRect().width - 20 : 100;
55
+ var maxHeightContainer = editorRootElement !== null ? editorRootElement.getBoundingClientRect().height - 20 : 100;
56
+ var minWidth = 100;
57
+ var minHeight = 100;
58
+ var setStartCursor = function setStartCursor(direction) {
59
+ var ew = direction === Direction.east || direction === Direction.west;
60
+ var ns = direction === Direction.north || direction === Direction.south;
61
+ var nwse = direction & Direction.north && direction & Direction.west || direction & Direction.south && direction & Direction.east;
62
+ var cursorDir = ew ? "ew" : ns ? "ns" : nwse ? "nwse" : "nesw";
63
+ if (editorRootElement !== null) {
64
+ editorRootElement.style.setProperty("cursor", "".concat(cursorDir, "-resize"), "important");
65
+ }
66
+ if (document.body !== null) {
67
+ document.body.style.setProperty("cursor", "".concat(cursorDir, "-resize"), "important");
68
+ userSelect.current.value = document.body.style.getPropertyValue("-webkit-user-select");
69
+ userSelect.current.priority = document.body.style.getPropertyPriority("-webkit-user-select");
70
+ document.body.style.setProperty("-webkit-user-select", "none", "important");
71
+ }
72
+ };
73
+ var setEndCursor = function setEndCursor() {
74
+ if (editorRootElement !== null) {
75
+ editorRootElement.style.setProperty("cursor", "text");
76
+ }
77
+ if (document.body !== null) {
78
+ document.body.style.setProperty("cursor", "default");
79
+ document.body.style.setProperty("-webkit-user-select", userSelect.current.value, userSelect.current.priority);
80
+ }
81
+ };
82
+ var handlePointerDown = function handlePointerDown(event, direction) {
83
+ if (!editor.isEditable()) {
84
+ return;
85
+ }
86
+ var image = imageRef.current;
87
+ var controlWrapper = controlWrapperRef.current;
88
+ if (image !== null && controlWrapper !== null) {
89
+ var _image$getBoundingCli = image.getBoundingClientRect(),
90
+ _width = _image$getBoundingCli.width,
91
+ _height = _image$getBoundingCli.height;
92
+ var positioning = positioningRef.current;
93
+ positioning.startWidth = _width;
94
+ positioning.startHeight = _height;
95
+ positioning.ratio = _width / _height;
96
+ positioning.currentWidth = _width;
97
+ positioning.currentHeight = _height;
98
+ positioning.startX = event.clientX;
99
+ positioning.startY = event.clientY;
100
+ positioning.isResizing = true;
101
+ positioning.direction = direction;
102
+ setStartCursor(direction);
103
+ onResizeStart();
104
+ controlWrapper.classList.add("image-control-wrapper--resizing");
105
+ image.style.height = "".concat(_height, "px");
106
+ image.style.width = "".concat(_width, "px");
107
+ document.addEventListener("pointermove", handlePointerMove);
108
+ document.addEventListener("pointerup", handlePointerUp);
109
+ }
110
+ };
111
+ var handlePointerMove = function handlePointerMove(event) {
112
+ var image = imageRef.current;
113
+ var positioning = positioningRef.current;
114
+ var isHorizontal = positioning.direction & (Direction.east | Direction.west);
115
+ var isVertical = positioning.direction & (Direction.south | Direction.north);
116
+ if (image !== null && positioning.isResizing) {
117
+ // Corner cursor
118
+ if (isHorizontal && isVertical) {
119
+ var diff = Math.floor(positioning.startX - event.clientX);
120
+ diff = positioning.direction & Direction.east ? -diff : diff;
121
+ var _width2 = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
122
+ var _height2 = _width2 / positioning.ratio;
123
+ image.style.width = "".concat(_width2, "px");
124
+ image.style.height = "".concat(_height2, "px");
125
+ positioning.currentHeight = _height2;
126
+ positioning.currentWidth = _width2;
127
+ } else if (isVertical) {
128
+ var _diff = Math.floor(positioning.startY - event.clientY);
129
+ _diff = positioning.direction & Direction.south ? -_diff : _diff;
130
+ var _height3 = clamp(positioning.startHeight + _diff, minHeight, maxHeightContainer);
131
+ image.style.height = "".concat(_height3, "px");
132
+ positioning.currentHeight = _height3;
133
+ } else {
134
+ var _diff2 = Math.floor(positioning.startX - event.clientX);
135
+ _diff2 = positioning.direction & Direction.east ? -_diff2 : _diff2;
136
+ var _width3 = clamp(positioning.startWidth + _diff2, minWidth, maxWidthContainer);
137
+ image.style.width = "".concat(_width3, "px");
138
+ positioning.currentWidth = _width3;
139
+ }
140
+ }
141
+ };
142
+ var handlePointerUp = function handlePointerUp() {
143
+ var image = imageRef.current;
144
+ var positioning = positioningRef.current;
145
+ var controlWrapper = controlWrapperRef.current;
146
+ if (image !== null && controlWrapper !== null && positioning.isResizing) {
147
+ var _width4 = positioning.currentWidth;
148
+ var _height4 = positioning.currentHeight;
149
+ positioning.startWidth = 0;
150
+ positioning.startHeight = 0;
151
+ positioning.ratio = 0;
152
+ positioning.startX = 0;
153
+ positioning.startY = 0;
154
+ positioning.currentWidth = 0;
155
+ positioning.currentHeight = 0;
156
+ positioning.isResizing = false;
157
+ controlWrapper.classList.remove("image-control-wrapper--resizing");
158
+ setEndCursor();
159
+ onResizeEnd(_width4, _height4);
160
+ document.removeEventListener("pointermove", handlePointerMove);
161
+ document.removeEventListener("pointerup", handlePointerUp);
162
+ }
163
+ };
164
+ return /*#__PURE__*/React.createElement("div", {
165
+ ref: controlWrapperRef
166
+ }, !showCaption && captionsEnabled && /*#__PURE__*/React.createElement("button", {
167
+ className: "image-caption-button",
168
+ ref: buttonRef,
169
+ onClick: function onClick() {
170
+ setShowCaption(!showCaption);
171
+ }
172
+ }, "Add Caption"), /*#__PURE__*/React.createElement("div", {
173
+ className: "image-resizer image-resizer-n",
174
+ onPointerDown: function onPointerDown(event) {
175
+ handlePointerDown(event, Direction.north);
176
+ }
177
+ }), /*#__PURE__*/React.createElement("div", {
178
+ className: "image-resizer image-resizer-ne",
179
+ onPointerDown: function onPointerDown(event) {
180
+ handlePointerDown(event, Direction.north | Direction.east);
181
+ }
182
+ }), /*#__PURE__*/React.createElement("div", {
183
+ className: "image-resizer image-resizer-e",
184
+ onPointerDown: function onPointerDown(event) {
185
+ handlePointerDown(event, Direction.east);
186
+ }
187
+ }), /*#__PURE__*/React.createElement("div", {
188
+ className: "image-resizer image-resizer-se",
189
+ onPointerDown: function onPointerDown(event) {
190
+ handlePointerDown(event, Direction.south | Direction.east);
191
+ }
192
+ }), /*#__PURE__*/React.createElement("div", {
193
+ className: "image-resizer image-resizer-s",
194
+ onPointerDown: function onPointerDown(event) {
195
+ handlePointerDown(event, Direction.south);
196
+ }
197
+ }), /*#__PURE__*/React.createElement("div", {
198
+ className: "image-resizer image-resizer-sw",
199
+ onPointerDown: function onPointerDown(event) {
200
+ handlePointerDown(event, Direction.south | Direction.west);
201
+ }
202
+ }), /*#__PURE__*/React.createElement("div", {
203
+ className: "image-resizer image-resizer-w",
204
+ onPointerDown: function onPointerDown(event) {
205
+ handlePointerDown(event, Direction.west);
206
+ }
207
+ }), /*#__PURE__*/React.createElement("div", {
208
+ className: "image-resizer image-resizer-nw",
209
+ onPointerDown: function onPointerDown(event) {
210
+ handlePointerDown(event, Direction.north | Direction.west);
211
+ }
212
+ }));
213
+ }
214
+
215
+ //# sourceMappingURL=ImageResizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","_interopRequireWildcard","require","clamp","value","min","max","Math","Direction","east","north","south","west","ImageResizer","_ref","onResizeStart","onResizeEnd","buttonRef","imageRef","maxWidth","editor","showCaption","setShowCaption","captionsEnabled","controlWrapperRef","useRef","userSelect","priority","positioningRef","currentHeight","currentWidth","direction","isResizing","ratio","startHeight","startWidth","startX","startY","editorRootElement","getRootElement","maxWidthContainer","getBoundingClientRect","width","maxHeightContainer","height","minWidth","minHeight","setStartCursor","ew","ns","nwse","cursorDir","style","setProperty","concat","document","body","current","getPropertyValue","getPropertyPriority","setEndCursor","handlePointerDown","event","isEditable","image","controlWrapper","_image$getBoundingCli","positioning","clientX","clientY","classList","add","addEventListener","handlePointerMove","handlePointerUp","isHorizontal","isVertical","diff","floor","remove","removeEventListener","createElement","ref","className","onClick","onPointerDown"],"sources":["ImageResizer.tsx"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type { LexicalEditor } from \"lexical\";\n\nimport * as React from \"react\";\nimport { useRef } from \"react\";\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n}\n\nconst Direction = {\n east: 1 << 0,\n north: 1 << 3,\n south: 1 << 1,\n west: 1 << 2\n};\n\nexport function ImageResizer({\n onResizeStart,\n onResizeEnd,\n buttonRef,\n imageRef,\n maxWidth,\n editor,\n showCaption,\n setShowCaption,\n captionsEnabled\n}: {\n editor: LexicalEditor;\n buttonRef: { current: null | HTMLButtonElement };\n imageRef: { current: null | HTMLElement };\n maxWidth?: number;\n onResizeEnd: (width: \"inherit\" | number, height: \"inherit\" | number) => void;\n onResizeStart: () => void;\n setShowCaption: (show: boolean) => void;\n showCaption: boolean;\n captionsEnabled: boolean;\n}): JSX.Element {\n const controlWrapperRef = useRef<HTMLDivElement>(null);\n const userSelect = useRef({\n priority: \"\",\n value: \"default\"\n });\n const positioningRef = useRef<{\n currentHeight: \"inherit\" | number;\n currentWidth: \"inherit\" | number;\n direction: number;\n isResizing: boolean;\n ratio: number;\n startHeight: number;\n startWidth: number;\n startX: number;\n startY: number;\n }>({\n currentHeight: 0,\n currentWidth: 0,\n direction: 0,\n isResizing: false,\n ratio: 0,\n startHeight: 0,\n startWidth: 0,\n startX: 0,\n startY: 0\n });\n const editorRootElement = editor.getRootElement();\n // Find max width, accounting for editor padding.\n const maxWidthContainer = maxWidth\n ? maxWidth\n : editorRootElement !== null\n ? editorRootElement.getBoundingClientRect().width - 20\n : 100;\n const maxHeightContainer =\n editorRootElement !== null ? editorRootElement.getBoundingClientRect().height - 20 : 100;\n\n const minWidth = 100;\n const minHeight = 100;\n\n const setStartCursor = (direction: number) => {\n const ew = direction === Direction.east || direction === Direction.west;\n const ns = direction === Direction.north || direction === Direction.south;\n const nwse =\n (direction & Direction.north && direction & Direction.west) ||\n (direction & Direction.south && direction & Direction.east);\n\n const cursorDir = ew ? \"ew\" : ns ? \"ns\" : nwse ? \"nwse\" : \"nesw\";\n\n if (editorRootElement !== null) {\n editorRootElement.style.setProperty(\"cursor\", `${cursorDir}-resize`, \"important\");\n }\n if (document.body !== null) {\n document.body.style.setProperty(\"cursor\", `${cursorDir}-resize`, \"important\");\n userSelect.current.value = document.body.style.getPropertyValue(\"-webkit-user-select\");\n userSelect.current.priority =\n document.body.style.getPropertyPriority(\"-webkit-user-select\");\n document.body.style.setProperty(\"-webkit-user-select\", `none`, \"important\");\n }\n };\n\n const setEndCursor = () => {\n if (editorRootElement !== null) {\n editorRootElement.style.setProperty(\"cursor\", \"text\");\n }\n if (document.body !== null) {\n document.body.style.setProperty(\"cursor\", \"default\");\n document.body.style.setProperty(\n \"-webkit-user-select\",\n userSelect.current.value,\n userSelect.current.priority\n );\n }\n };\n\n const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>, direction: number) => {\n if (!editor.isEditable()) {\n return;\n }\n\n const image = imageRef.current;\n const controlWrapper = controlWrapperRef.current;\n\n if (image !== null && controlWrapper !== null) {\n const { width, height } = image.getBoundingClientRect();\n const positioning = positioningRef.current;\n positioning.startWidth = width;\n positioning.startHeight = height;\n positioning.ratio = width / height;\n positioning.currentWidth = width;\n positioning.currentHeight = height;\n positioning.startX = event.clientX;\n positioning.startY = event.clientY;\n positioning.isResizing = true;\n positioning.direction = direction;\n\n setStartCursor(direction);\n onResizeStart();\n\n controlWrapper.classList.add(\"image-control-wrapper--resizing\");\n image.style.height = `${height}px`;\n image.style.width = `${width}px`;\n\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handlePointerUp);\n }\n };\n const handlePointerMove = (event: PointerEvent) => {\n const image = imageRef.current;\n const positioning = positioningRef.current;\n\n const isHorizontal = positioning.direction & (Direction.east | Direction.west);\n const isVertical = positioning.direction & (Direction.south | Direction.north);\n\n if (image !== null && positioning.isResizing) {\n // Corner cursor\n if (isHorizontal && isVertical) {\n let diff = Math.floor(positioning.startX - event.clientX);\n diff = positioning.direction & Direction.east ? -diff : diff;\n\n const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);\n\n const height = width / positioning.ratio;\n image.style.width = `${width}px`;\n image.style.height = `${height}px`;\n positioning.currentHeight = height;\n positioning.currentWidth = width;\n } else if (isVertical) {\n let diff = Math.floor(positioning.startY - event.clientY);\n diff = positioning.direction & Direction.south ? -diff : diff;\n\n const height = clamp(positioning.startHeight + diff, minHeight, maxHeightContainer);\n\n image.style.height = `${height}px`;\n positioning.currentHeight = height;\n } else {\n let diff = Math.floor(positioning.startX - event.clientX);\n diff = positioning.direction & Direction.east ? -diff : diff;\n\n const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);\n\n image.style.width = `${width}px`;\n positioning.currentWidth = width;\n }\n }\n };\n const handlePointerUp = () => {\n const image = imageRef.current;\n const positioning = positioningRef.current;\n const controlWrapper = controlWrapperRef.current;\n if (image !== null && controlWrapper !== null && positioning.isResizing) {\n const width = positioning.currentWidth;\n const height = positioning.currentHeight;\n positioning.startWidth = 0;\n positioning.startHeight = 0;\n positioning.ratio = 0;\n positioning.startX = 0;\n positioning.startY = 0;\n positioning.currentWidth = 0;\n positioning.currentHeight = 0;\n positioning.isResizing = false;\n\n controlWrapper.classList.remove(\"image-control-wrapper--resizing\");\n\n setEndCursor();\n onResizeEnd(width, height);\n\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handlePointerUp);\n }\n };\n return (\n <div ref={controlWrapperRef}>\n {!showCaption && captionsEnabled && (\n <button\n className=\"image-caption-button\"\n ref={buttonRef}\n onClick={() => {\n setShowCaption(!showCaption);\n }}\n >\n Add Caption\n </button>\n )}\n <div\n className=\"image-resizer image-resizer-n\"\n onPointerDown={event => {\n handlePointerDown(event, Direction.north);\n }}\n />\n <div\n className=\"image-resizer image-resizer-ne\"\n onPointerDown={event => {\n handlePointerDown(event, Direction.north | Direction.east);\n }}\n />\n <div\n className=\"image-resizer image-resizer-e\"\n onPointerDown={event => {\n handlePointerDown(event, Direction.east);\n }}\n />\n <div\n className=\"image-resizer image-resizer-se\"\n onPointerDown={event => {\n handlePointerDown(event, Direction.south | Direction.east);\n }}\n />\n <div\n className=\"image-resizer image-resizer-s\"\n onPointerDown={event => {\n handlePointerDown(event, Direction.south);\n }}\n />\n <div\n className=\"image-resizer image-resizer-sw\"\n onPointerDown={event => {\n handlePointerDown(event, Direction.south | Direction.west);\n }}\n />\n <div\n className=\"image-resizer image-resizer-w\"\n onPointerDown={event => {\n handlePointerDown(event, Direction.west);\n }}\n />\n <div\n className=\"image-resizer image-resizer-nw\"\n onPointerDown={event => {\n handlePointerDown(event, Direction.north | Direction.west);\n }}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;AAUA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAVA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASC,KAAKA,CAACC,KAAa,EAAEC,GAAW,EAAEC,GAAW,EAAE;EACpD,OAAOC,IAAI,CAACF,GAAG,CAACE,IAAI,CAACD,GAAG,CAACF,KAAK,EAAEC,GAAG,CAAC,EAAEC,GAAG,CAAC;AAC9C;AAEA,IAAME,SAA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AAAvB,KAAK,EAAI;MACpBD,iBAAiB,CAACC,KAAK,EAAEtD,SAAS,CAACG,KAAK,CAAC;IAC7C;EAAE,CACL,CAAC,eACFX,KAAA,CAAAiF,aAAA;IACIE,SAAS,EAAC,gCAAgC;IAC1CE,aAAa,EAAE,SAAAA,cAAAvB,KAAK,EAAI;MACpBD,iBAAiB,CAACC,KAAK,EAAEtD,SAAS,CAACG,KAAK,GAAGH,SAAS,CAACI,IAAI,CAAC;IAC9D;EAAE,CACL,CAAC,eACFZ,KAAA,CAAAiF,aAAA;IACIE,SAAS,EAAC,+BAA+B;IACzCE,aAAa,EAAE,SAAAA,cAAAvB,KAAK,EAAI;MACpBD,iBAAiB,CAACC,KAAK,EAAEtD,SAAS,CAACI,IAAI,CAAC;IAC5C;EAAE,CACL,CAAC,eACFZ,KAAA,CAAAiF,aAAA;IACIE,SAAS,EAAC,gCAAgC;IAC1CE,aAAa,EAAE,SAAAA,cAAAvB,KAAK,EAAI;MACpBD,iBAAiB,CAACC,KAAK,EAAEtD,SAAS,CAACE,KAAK,GAAGF,SAAS,CAACI,IAAI,CAAC;IAC9D;EAAE,CACL,CACA,CAAC;AAEd"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ .Placeholder__root {
11
+ font-size: 15px;
12
+ margin-top: -20px;
13
+ color: #999;
14
+ overflow: hidden;
15
+ position: relative;
16
+ text-overflow: ellipsis;
17
+ user-select: none;
18
+ white-space: nowrap;
19
+ pointer-events: none;
20
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import "./Placeholder.css";
9
+ import * as React from "react";
10
+ import { ReactNode } from "react";
11
+ export declare function Placeholder({ children, className, styles }: {
12
+ children: ReactNode;
13
+ className?: string;
14
+ styles?: React.CSSProperties;
15
+ }): JSX.Element;