@webiny/lexical-editor 6.0.0-beta.0 → 6.0.0-rc.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 +6 -12
- package/commands/image.d.ts +2 -2
- package/commands/image.js +2 -8
- package/commands/image.js.map +1 -1
- package/commands/index.d.ts +5 -3
- package/commands/index.js +5 -38
- package/commands/index.js.map +1 -1
- package/commands/list.d.ts +2 -2
- package/commands/list.js +4 -10
- package/commands/list.js.map +1 -1
- package/commands/quote.d.ts +2 -2
- package/commands/quote.js +2 -8
- package/commands/quote.js.map +1 -1
- package/commands/toolbar.d.ts +1 -0
- package/commands/toolbar.js +4 -0
- package/commands/toolbar.js.map +1 -0
- package/commands/typography.d.ts +8 -0
- package/commands/typography.js +4 -0
- package/commands/typography.js.map +1 -0
- package/components/Editor/EnsureHeadingTagPlugin.d.ts +6 -0
- package/components/Editor/EnsureHeadingTagPlugin.js +20 -0
- package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -0
- package/components/Editor/RichTextEditor.d.ts +29 -12
- package/components/Editor/RichTextEditor.js +89 -110
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/Editor/normalizeInputValue.d.ts +6 -0
- package/components/Editor/normalizeInputValue.js +16 -0
- package/components/Editor/normalizeInputValue.js.map +1 -0
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +14 -16
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +21 -69
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
- package/components/LexicalEditorConfig/components/Node.d.ts +1 -1
- package/components/LexicalEditorConfig/components/Node.js +17 -26
- package/components/LexicalEditorConfig/components/Node.js.map +1 -1
- package/components/LexicalEditorConfig/components/Plugin.js +17 -26
- package/components/LexicalEditorConfig/components/Plugin.js.map +1 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js +17 -26
- package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -1
- package/components/LexicalHtmlRenderer.d.ts +5 -8
- package/components/LexicalHtmlRenderer.js +35 -50
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/StaticToolbar.css +416 -0
- package/components/Toolbar/StaticToolbar.d.ts +3 -1
- package/components/Toolbar/StaticToolbar.js +19 -23
- package/components/Toolbar/StaticToolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.js +16 -21
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +25 -31
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.js +16 -21
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- package/components/ToolbarActions/FontColorAction.d.ts +16 -4
- package/components/ToolbarActions/FontColorAction.js +32 -43
- package/components/ToolbarActions/FontColorAction.js.map +1 -1
- package/components/ToolbarActions/ImageAction.js +19 -34
- package/components/ToolbarActions/ImageAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.js +16 -21
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.js +19 -24
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +25 -36
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +20 -25
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.d.ts +16 -4
- package/components/ToolbarActions/TextAlignmentAction.js +36 -45
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.d.ts +16 -4
- package/components/ToolbarActions/TypographyAction.js +57 -79
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/components/ToolbarActions/UnderlineAction.js +16 -21
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/context/FontColorActionContext.js +2 -9
- package/context/FontColorActionContext.js.map +1 -1
- package/context/RichTextEditorContext.d.ts +7 -8
- package/context/RichTextEditorContext.js +28 -26
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.d.ts +3 -3
- package/context/SharedHistoryContext.js +12 -20
- package/context/SharedHistoryContext.js.map +1 -1
- package/context/TextAlignmentActionContextProps.d.ts +1 -1
- package/context/TextAlignmentActionContextProps.js +2 -9
- package/context/TextAlignmentActionContextProps.js.map +1 -1
- package/context/TypographyActionContext.d.ts +3 -2
- package/context/TypographyActionContext.js +2 -9
- package/context/TypographyActionContext.js.map +1 -1
- package/exports/admin/lexical.d.ts +15 -0
- package/exports/admin/lexical.js +23 -0
- package/exports/admin/lexical.js.map +1 -0
- package/hooks/index.d.ts +7 -8
- package/hooks/index.js +7 -93
- package/hooks/index.js.map +1 -1
- package/hooks/useCurrentElement.d.ts +3 -3
- package/hooks/useCurrentElement.js +11 -18
- package/hooks/useCurrentElement.js.map +1 -1
- package/hooks/useCurrentSelection.d.ts +2 -1
- package/hooks/useCurrentSelection.js +27 -40
- package/hooks/useCurrentSelection.js.map +1 -1
- package/hooks/useFontColorPicker.d.ts +1 -1
- package/hooks/useFontColorPicker.js +5 -11
- package/hooks/useFontColorPicker.js.map +1 -1
- package/hooks/useIsMounted.js +6 -14
- package/hooks/useIsMounted.js.map +1 -1
- package/hooks/useRichTextEditor.d.ts +1 -1
- package/hooks/useRichTextEditor.js +5 -11
- package/hooks/useRichTextEditor.js.map +1 -1
- package/hooks/useTextAlignmentAction.d.ts +1 -1
- package/hooks/useTextAlignmentAction.js +5 -11
- package/hooks/useTextAlignmentAction.js.map +1 -1
- package/hooks/useTypographyAction.d.ts +1 -1
- package/hooks/useTypographyAction.js +5 -11
- package/hooks/useTypographyAction.js.map +1 -1
- package/index.d.ts +33 -38
- package/index.js +44 -322
- package/index.js.map +1 -1
- package/package.json +18 -22
- package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +2 -2
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +16 -22
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +9 -14
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/index.d.ts +1 -1
- package/plugins/CodeHighlightPlugin/index.js +1 -16
- package/plugins/CodeHighlightPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +10 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +28 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +7 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +61 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +2 -136
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +4 -16
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +7 -180
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +1 -16
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +2 -8
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/types.d.ts +10 -0
- package/plugins/FloatingLinkEditorPlugin/types.js +3 -0
- package/plugins/FloatingLinkEditorPlugin/types.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +8 -2
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +119 -63
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +1 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js +19 -28
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToNode.d.ts +3 -0
- package/plugins/FontColorPlugin/applyColorToNode.js +8 -0
- package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -0
- package/plugins/FontColorPlugin/applyColorToSelection.d.ts +3 -0
- package/plugins/FontColorPlugin/applyColorToSelection.js +66 -0
- package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -0
- package/plugins/ImagesPlugin/ImagesPlugin.d.ts +2 -3
- package/plugins/ImagesPlugin/ImagesPlugin.js +58 -60
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LinkPlugin/LinkPlugin.d.ts +1 -1
- package/plugins/LinkPlugin/LinkPlugin.js +29 -37
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
- package/plugins/ListPLugin/ListPlugin.js +52 -15
- package/plugins/ListPLugin/ListPlugin.js.map +1 -1
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +19 -16
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
- package/plugins/StateHandlingPlugin.d.ts +8 -0
- package/plugins/StateHandlingPlugin.js +75 -0
- package/plugins/StateHandlingPlugin.js.map +1 -0
- package/plugins/TypographyPlugin/TypographyPlugin.js +17 -21
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/types.d.ts +8 -8
- package/types.js +6 -38
- package/types.js.map +1 -1
- package/ui/ContentEditable.d.ts +0 -1
- package/ui/ContentEditable.js +7 -14
- package/ui/ContentEditable.js.map +1 -1
- package/ui/Divider.d.ts +0 -1
- package/ui/Divider.js +3 -10
- package/ui/Divider.js.map +1 -1
- package/ui/DropDown.d.ts +1 -1
- package/ui/DropDown.js +64 -90
- package/ui/DropDown.js.map +1 -1
- package/ui/ImageResizer.d.ts +0 -1
- package/ui/ImageResizer.js +84 -89
- package/ui/ImageResizer.js.map +1 -1
- package/ui/LinkPreview.d.ts +0 -1
- package/ui/LinkPreview.js +22 -29
- package/ui/LinkPreview.js.map +1 -1
- package/ui/Placeholder.d.ts +1 -1
- package/ui/Placeholder.js +10 -16
- package/ui/Placeholder.js.map +1 -1
- package/ui/TextInput.d.ts +1 -2
- package/ui/TextInput.js +11 -18
- package/ui/TextInput.js.map +1 -1
- package/ui/ToolbarActionDialog.js +30 -42
- package/ui/ToolbarActionDialog.js.map +1 -1
- package/utils/canUseDOM.js +1 -7
- package/utils/canUseDOM.js.map +1 -1
- package/utils/files.d.ts +6 -7
- package/utils/files.js +5 -56
- package/utils/files.js.map +1 -1
- package/utils/getDOMRangeRect.js +4 -10
- package/utils/getDOMRangeRect.js.map +1 -1
- package/utils/getSelectedNode.d.ts +1 -1
- package/utils/getSelectedNode.js +9 -16
- package/utils/getSelectedNode.js.map +1 -1
- package/utils/getTransparentImage.js +1 -7
- package/utils/getTransparentImage.js.map +1 -1
- package/utils/insertImage.d.ts +1 -1
- package/utils/insertImage.js +8 -14
- package/utils/insertImage.js.map +1 -1
- package/utils/isAnchorLink.js +1 -7
- package/utils/isAnchorLink.js.map +1 -1
- package/utils/isChildOfFloatingToolbar.js +2 -8
- package/utils/isChildOfFloatingToolbar.js.map +1 -1
- package/utils/isHTMLElement.js +1 -7
- package/utils/isHTMLElement.js.map +1 -1
- package/utils/isValidJSON.js +3 -9
- package/utils/isValidJSON.js.map +1 -1
- package/utils/isValidLexicalData.d.ts +3 -3
- package/utils/isValidLexicalData.js +6 -12
- package/utils/isValidLexicalData.js.map +1 -1
- package/utils/point.js +35 -60
- package/utils/point.js.map +1 -1
- package/utils/rect.d.ts +2 -2
- package/utils/rect.js +115 -149
- package/utils/rect.js.map +1 -1
- package/utils/sanitizeUrl.js +6 -13
- package/utils/sanitizeUrl.js.map +1 -1
- package/utils/setFloatingElemPosition.d.ts +1 -1
- package/utils/setFloatingElemPosition.js +29 -39
- package/utils/setFloatingElemPosition.js.map +1 -1
- package/components/Editor/HeadingEditor.d.ts +0 -7
- package/components/Editor/HeadingEditor.js +0 -29
- package/components/Editor/HeadingEditor.js.map +0 -1
- package/components/Editor/ParagraphEditor.d.ts +0 -7
- package/components/Editor/ParagraphEditor.js +0 -29
- package/components/Editor/ParagraphEditor.js.map +0 -1
- package/components/Toolbar/Toolbar.css +0 -647
- package/components/Toolbar/Toolbar.d.ts +0 -6
- package/components/Toolbar/Toolbar.js +0 -162
- package/components/Toolbar/Toolbar.js.map +0 -1
- package/components/ToolbarActions/FontSizeAction.d.ts +0 -2
- package/components/ToolbarActions/FontSizeAction.js +0 -88
- package/components/ToolbarActions/FontSizeAction.js.map +0 -1
- package/hooks/useList.d.ts +0 -2
- package/hooks/useList.js +0 -54
- package/hooks/useList.js.map +0 -1
- package/hooks/useQuote.d.ts +0 -2
- package/hooks/useQuote.js +0 -22
- package/hooks/useQuote.js.map +0 -1
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +0 -9
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +0 -118
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +0 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +0 -9
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +0 -44
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +0 -1
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.d.ts +0 -9
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js +0 -45
- package/plugins/LexicalUpdateStatePlugin/UpdateStatePlugin.js.map +0 -1
- package/plugins/LexicalUpdateStatePlugin/index.d.ts +0 -1
- package/plugins/LexicalUpdateStatePlugin/index.js +0 -18
- package/plugins/LexicalUpdateStatePlugin/index.js.map +0 -1
- package/utils/generateInitialLexicalValue.d.ts +0 -5
- package/utils/generateInitialLexicalValue.js +0 -33
- package/utils/generateInitialLexicalValue.js.map +0 -1
package/ui/ImageResizer.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
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
|
-
var React = _react;
|
|
10
1
|
/**
|
|
11
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
12
3
|
*
|
|
@@ -15,31 +6,34 @@ var React = _react;
|
|
|
15
6
|
*
|
|
16
7
|
*/
|
|
17
8
|
|
|
9
|
+
import * as React from "react";
|
|
10
|
+
import { useRef } from "react";
|
|
18
11
|
function clamp(value, min, max) {
|
|
19
12
|
return Math.min(Math.max(value, min), max);
|
|
20
13
|
}
|
|
21
|
-
|
|
14
|
+
const Direction = {
|
|
22
15
|
east: 1 << 0,
|
|
23
16
|
north: 1 << 3,
|
|
24
17
|
south: 1 << 1,
|
|
25
18
|
west: 1 << 2
|
|
26
19
|
};
|
|
27
|
-
function ImageResizer(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
export function ImageResizer({
|
|
21
|
+
onResizeStart,
|
|
22
|
+
onResizeEnd,
|
|
23
|
+
buttonRef,
|
|
24
|
+
imageRef,
|
|
25
|
+
maxWidth,
|
|
26
|
+
editor,
|
|
27
|
+
showCaption,
|
|
28
|
+
setShowCaption,
|
|
29
|
+
captionsEnabled
|
|
30
|
+
}) {
|
|
31
|
+
const controlWrapperRef = useRef(null);
|
|
32
|
+
const userSelect = useRef({
|
|
39
33
|
priority: "",
|
|
40
34
|
value: "default"
|
|
41
35
|
});
|
|
42
|
-
|
|
36
|
+
const positioningRef = useRef({
|
|
43
37
|
currentHeight: 0,
|
|
44
38
|
currentWidth: 0,
|
|
45
39
|
direction: 0,
|
|
@@ -50,28 +44,28 @@ function ImageResizer(_ref) {
|
|
|
50
44
|
startX: 0,
|
|
51
45
|
startY: 0
|
|
52
46
|
});
|
|
53
|
-
|
|
47
|
+
const editorRootElement = editor.getRootElement();
|
|
54
48
|
// Find max width, accounting for editor padding.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
const maxWidthContainer = maxWidth ? maxWidth : editorRootElement !== null ? editorRootElement.getBoundingClientRect().width - 20 : 100;
|
|
50
|
+
const maxHeightContainer = editorRootElement !== null ? editorRootElement.getBoundingClientRect().height - 20 : 100;
|
|
51
|
+
const minWidth = 100;
|
|
52
|
+
const minHeight = 100;
|
|
53
|
+
const setStartCursor = direction => {
|
|
54
|
+
const ew = direction === Direction.east || direction === Direction.west;
|
|
55
|
+
const ns = direction === Direction.north || direction === Direction.south;
|
|
56
|
+
const nwse = direction & Direction.north && direction & Direction.west || direction & Direction.south && direction & Direction.east;
|
|
57
|
+
const cursorDir = ew ? "ew" : ns ? "ns" : nwse ? "nwse" : "nesw";
|
|
64
58
|
if (editorRootElement !== null) {
|
|
65
|
-
editorRootElement.style.setProperty("cursor",
|
|
59
|
+
editorRootElement.style.setProperty("cursor", `${cursorDir}-resize`, "important");
|
|
66
60
|
}
|
|
67
61
|
if (document.body !== null) {
|
|
68
|
-
document.body.style.setProperty("cursor",
|
|
62
|
+
document.body.style.setProperty("cursor", `${cursorDir}-resize`, "important");
|
|
69
63
|
userSelect.current.value = document.body.style.getPropertyValue("-webkit-user-select");
|
|
70
64
|
userSelect.current.priority = document.body.style.getPropertyPriority("-webkit-user-select");
|
|
71
|
-
document.body.style.setProperty("-webkit-user-select",
|
|
65
|
+
document.body.style.setProperty("-webkit-user-select", `none`, "important");
|
|
72
66
|
}
|
|
73
67
|
};
|
|
74
|
-
|
|
68
|
+
const setEndCursor = () => {
|
|
75
69
|
if (editorRootElement !== null) {
|
|
76
70
|
editorRootElement.style.setProperty("cursor", "text");
|
|
77
71
|
}
|
|
@@ -80,22 +74,23 @@ function ImageResizer(_ref) {
|
|
|
80
74
|
document.body.style.setProperty("-webkit-user-select", userSelect.current.value, userSelect.current.priority);
|
|
81
75
|
}
|
|
82
76
|
};
|
|
83
|
-
|
|
77
|
+
const handlePointerDown = (event, direction) => {
|
|
84
78
|
if (!editor.isEditable()) {
|
|
85
79
|
return;
|
|
86
80
|
}
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
const image = imageRef.current;
|
|
82
|
+
const controlWrapper = controlWrapperRef.current;
|
|
89
83
|
if (image !== null && controlWrapper !== null) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
positioning
|
|
95
|
-
positioning.
|
|
96
|
-
positioning.
|
|
97
|
-
positioning.
|
|
98
|
-
positioning.
|
|
84
|
+
const {
|
|
85
|
+
width,
|
|
86
|
+
height
|
|
87
|
+
} = image.getBoundingClientRect();
|
|
88
|
+
const positioning = positioningRef.current;
|
|
89
|
+
positioning.startWidth = width;
|
|
90
|
+
positioning.startHeight = height;
|
|
91
|
+
positioning.ratio = width / height;
|
|
92
|
+
positioning.currentWidth = width;
|
|
93
|
+
positioning.currentHeight = height;
|
|
99
94
|
positioning.startX = event.clientX;
|
|
100
95
|
positioning.startY = event.clientY;
|
|
101
96
|
positioning.isResizing = true;
|
|
@@ -103,50 +98,50 @@ function ImageResizer(_ref) {
|
|
|
103
98
|
setStartCursor(direction);
|
|
104
99
|
onResizeStart();
|
|
105
100
|
controlWrapper.classList.add("image-control-wrapper--resizing");
|
|
106
|
-
image.style.height =
|
|
107
|
-
image.style.width =
|
|
101
|
+
image.style.height = `${height}px`;
|
|
102
|
+
image.style.width = `${width}px`;
|
|
108
103
|
document.addEventListener("pointermove", handlePointerMove);
|
|
109
104
|
document.addEventListener("pointerup", handlePointerUp);
|
|
110
105
|
}
|
|
111
106
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
107
|
+
const handlePointerMove = event => {
|
|
108
|
+
const image = imageRef.current;
|
|
109
|
+
const positioning = positioningRef.current;
|
|
110
|
+
const isHorizontal = positioning.direction & (Direction.east | Direction.west);
|
|
111
|
+
const isVertical = positioning.direction & (Direction.south | Direction.north);
|
|
117
112
|
if (image !== null && positioning.isResizing) {
|
|
118
113
|
// Corner cursor
|
|
119
114
|
if (isHorizontal && isVertical) {
|
|
120
|
-
|
|
115
|
+
let diff = Math.floor(positioning.startX - event.clientX);
|
|
121
116
|
diff = positioning.direction & Direction.east ? -diff : diff;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
image.style.width =
|
|
125
|
-
image.style.height =
|
|
126
|
-
positioning.currentHeight =
|
|
127
|
-
positioning.currentWidth =
|
|
117
|
+
const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
|
|
118
|
+
const height = width / positioning.ratio;
|
|
119
|
+
image.style.width = `${width}px`;
|
|
120
|
+
image.style.height = `${height}px`;
|
|
121
|
+
positioning.currentHeight = height;
|
|
122
|
+
positioning.currentWidth = width;
|
|
128
123
|
} else if (isVertical) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
image.style.height =
|
|
133
|
-
positioning.currentHeight =
|
|
124
|
+
let diff = Math.floor(positioning.startY - event.clientY);
|
|
125
|
+
diff = positioning.direction & Direction.south ? -diff : diff;
|
|
126
|
+
const height = clamp(positioning.startHeight + diff, minHeight, maxHeightContainer);
|
|
127
|
+
image.style.height = `${height}px`;
|
|
128
|
+
positioning.currentHeight = height;
|
|
134
129
|
} else {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
image.style.width =
|
|
139
|
-
positioning.currentWidth =
|
|
130
|
+
let diff = Math.floor(positioning.startX - event.clientX);
|
|
131
|
+
diff = positioning.direction & Direction.east ? -diff : diff;
|
|
132
|
+
const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
|
|
133
|
+
image.style.width = `${width}px`;
|
|
134
|
+
positioning.currentWidth = width;
|
|
140
135
|
}
|
|
141
136
|
}
|
|
142
137
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
const handlePointerUp = () => {
|
|
139
|
+
const image = imageRef.current;
|
|
140
|
+
const positioning = positioningRef.current;
|
|
141
|
+
const controlWrapper = controlWrapperRef.current;
|
|
147
142
|
if (image !== null && controlWrapper !== null && positioning.isResizing) {
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
const width = positioning.currentWidth;
|
|
144
|
+
const height = positioning.currentHeight;
|
|
150
145
|
positioning.startWidth = 0;
|
|
151
146
|
positioning.startHeight = 0;
|
|
152
147
|
positioning.ratio = 0;
|
|
@@ -157,7 +152,7 @@ function ImageResizer(_ref) {
|
|
|
157
152
|
positioning.isResizing = false;
|
|
158
153
|
controlWrapper.classList.remove("image-control-wrapper--resizing");
|
|
159
154
|
setEndCursor();
|
|
160
|
-
onResizeEnd(
|
|
155
|
+
onResizeEnd(width, height);
|
|
161
156
|
document.removeEventListener("pointermove", handlePointerMove);
|
|
162
157
|
document.removeEventListener("pointerup", handlePointerUp);
|
|
163
158
|
}
|
|
@@ -167,47 +162,47 @@ function ImageResizer(_ref) {
|
|
|
167
162
|
}, !showCaption && captionsEnabled && /*#__PURE__*/React.createElement("button", {
|
|
168
163
|
className: "image-caption-button",
|
|
169
164
|
ref: buttonRef,
|
|
170
|
-
onClick:
|
|
165
|
+
onClick: () => {
|
|
171
166
|
setShowCaption(!showCaption);
|
|
172
167
|
}
|
|
173
168
|
}, "Add Caption"), /*#__PURE__*/React.createElement("div", {
|
|
174
169
|
className: "image-resizer image-resizer-n",
|
|
175
|
-
onPointerDown:
|
|
170
|
+
onPointerDown: event => {
|
|
176
171
|
handlePointerDown(event, Direction.north);
|
|
177
172
|
}
|
|
178
173
|
}), /*#__PURE__*/React.createElement("div", {
|
|
179
174
|
className: "image-resizer image-resizer-ne",
|
|
180
|
-
onPointerDown:
|
|
175
|
+
onPointerDown: event => {
|
|
181
176
|
handlePointerDown(event, Direction.north | Direction.east);
|
|
182
177
|
}
|
|
183
178
|
}), /*#__PURE__*/React.createElement("div", {
|
|
184
179
|
className: "image-resizer image-resizer-e",
|
|
185
|
-
onPointerDown:
|
|
180
|
+
onPointerDown: event => {
|
|
186
181
|
handlePointerDown(event, Direction.east);
|
|
187
182
|
}
|
|
188
183
|
}), /*#__PURE__*/React.createElement("div", {
|
|
189
184
|
className: "image-resizer image-resizer-se",
|
|
190
|
-
onPointerDown:
|
|
185
|
+
onPointerDown: event => {
|
|
191
186
|
handlePointerDown(event, Direction.south | Direction.east);
|
|
192
187
|
}
|
|
193
188
|
}), /*#__PURE__*/React.createElement("div", {
|
|
194
189
|
className: "image-resizer image-resizer-s",
|
|
195
|
-
onPointerDown:
|
|
190
|
+
onPointerDown: event => {
|
|
196
191
|
handlePointerDown(event, Direction.south);
|
|
197
192
|
}
|
|
198
193
|
}), /*#__PURE__*/React.createElement("div", {
|
|
199
194
|
className: "image-resizer image-resizer-sw",
|
|
200
|
-
onPointerDown:
|
|
195
|
+
onPointerDown: event => {
|
|
201
196
|
handlePointerDown(event, Direction.south | Direction.west);
|
|
202
197
|
}
|
|
203
198
|
}), /*#__PURE__*/React.createElement("div", {
|
|
204
199
|
className: "image-resizer image-resizer-w",
|
|
205
|
-
onPointerDown:
|
|
200
|
+
onPointerDown: event => {
|
|
206
201
|
handlePointerDown(event, Direction.west);
|
|
207
202
|
}
|
|
208
203
|
}), /*#__PURE__*/React.createElement("div", {
|
|
209
204
|
className: "image-resizer image-resizer-nw",
|
|
210
|
-
onPointerDown:
|
|
205
|
+
onPointerDown: event => {
|
|
211
206
|
handlePointerDown(event, Direction.north | Direction.west);
|
|
212
207
|
}
|
|
213
208
|
}));
|
package/ui/ImageResizer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","React","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,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,IAAAC,KAAA,GAAAH,MAAA;AAV/B;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASI,KAAKA,CAACC,KAA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,EAAEtD,SAAS,CAACG,KAAK,GAAGH,SAAS,CAACC,IAAI,CAAC;IAC9D;EAAE,CACL,CAAC,eACFP,KAAA,CAAA+E,aAAA;IACIE,SAAS,EAAC,+BAA+B;IACzCE,aAAa,EAAE,SAAAA,cAAAvB,KAAK,EAAI;MACpBD,iBAAiB,CAACC,KAAK,EAAEtD,SAAS,CAACG,KAAK,CAAC;IAC7C;EAAE,CACL,CAAC,eACFT,KAAA,CAAA+E,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,eACFV,KAAA,CAAA+E,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,eACFV,KAAA,CAAA+E,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","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","useRef","clamp","value","min","max","Math","Direction","east","north","south","west","ImageResizer","onResizeStart","onResizeEnd","buttonRef","imageRef","maxWidth","editor","showCaption","setShowCaption","captionsEnabled","controlWrapperRef","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","document","body","current","getPropertyValue","getPropertyPriority","setEndCursor","handlePointerDown","event","isEditable","image","controlWrapper","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":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,MAAM,QAAQ,OAAO;AAE9B,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,MAAME,SAAS,GAAG;EACdC,IAAI,EAAE,CAAC,IAAI,CAAC;EACZC,KAAK,EAAE,CAAC,IAAI,CAAC;EACbC,KAAK,EAAE,CAAC,IAAI,CAAC;EACbC,IAAI,EAAE,CAAC,IAAI;AACf,CAAC;AAED,OAAO,SAASC,YAAYA,CAAC;EACzBC,aAAa;EACbC,WAAW;EACXC,SAAS;EACTC,QA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-1,15 +1,3 @@
|
|
|
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.LinkPreview = LinkPreview;
|
|
9
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
-
require("./LinkPreview.css");
|
|
11
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
-
var React = _react;
|
|
13
1
|
/**
|
|
14
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
3
|
*
|
|
@@ -18,23 +6,24 @@ var React = _react;
|
|
|
18
6
|
*
|
|
19
7
|
*/
|
|
20
8
|
|
|
9
|
+
import "./LinkPreview.css";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
import { Suspense } from "react";
|
|
21
12
|
// Cached responses or running request promises
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const PREVIEW_CACHE = {};
|
|
14
|
+
const URL_MATCHER = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
24
15
|
function useSuspenseRequest(url) {
|
|
25
|
-
|
|
16
|
+
let cached = PREVIEW_CACHE[url];
|
|
26
17
|
if (!url.match(URL_MATCHER)) {
|
|
27
18
|
return {
|
|
28
19
|
preview: null
|
|
29
20
|
};
|
|
30
21
|
}
|
|
31
22
|
if (!cached) {
|
|
32
|
-
cached = PREVIEW_CACHE[url] = fetch(
|
|
33
|
-
return response.json();
|
|
34
|
-
}).then(function (preview) {
|
|
23
|
+
cached = PREVIEW_CACHE[url] = fetch(`/api/link-preview?url=${encodeURI(url)}`).then(response => response.json()).then(preview => {
|
|
35
24
|
PREVIEW_CACHE[url] = preview;
|
|
36
25
|
return preview;
|
|
37
|
-
}).catch(
|
|
26
|
+
}).catch(() => {
|
|
38
27
|
PREVIEW_CACHE[url] = {
|
|
39
28
|
preview: null
|
|
40
29
|
};
|
|
@@ -45,10 +34,12 @@ function useSuspenseRequest(url) {
|
|
|
45
34
|
}
|
|
46
35
|
return cached;
|
|
47
36
|
}
|
|
48
|
-
function LinkPreviewContent(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
37
|
+
function LinkPreviewContent({
|
|
38
|
+
url
|
|
39
|
+
}) {
|
|
40
|
+
const {
|
|
41
|
+
preview
|
|
42
|
+
} = useSuspenseRequest(url);
|
|
52
43
|
if (preview === null) {
|
|
53
44
|
return null;
|
|
54
45
|
}
|
|
@@ -72,14 +63,16 @@ function Glimmer(props) {
|
|
|
72
63
|
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
73
64
|
className: "CustomLinkPreview__glimmer"
|
|
74
65
|
}, props, {
|
|
75
|
-
style:
|
|
76
|
-
animationDelay: String((props.index || 0) * 300)
|
|
77
|
-
|
|
66
|
+
style: {
|
|
67
|
+
animationDelay: String((props.index || 0) * 300),
|
|
68
|
+
...(props.style || {})
|
|
69
|
+
}
|
|
78
70
|
}));
|
|
79
71
|
}
|
|
80
|
-
function LinkPreview(
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
export function LinkPreview({
|
|
73
|
+
url
|
|
74
|
+
}) {
|
|
75
|
+
return /*#__PURE__*/React.createElement(Suspense, {
|
|
83
76
|
fallback: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Glimmer, {
|
|
84
77
|
style: {
|
|
85
78
|
height: "80px"
|
package/ui/LinkPreview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","Suspense","PREVIEW_CACHE","URL_MATCHER","useSuspenseRequest","url","cached","match","preview","fetch","encodeURI","then","response","json","catch","Promise","LinkPreviewContent","createElement","className","img","src","alt","title","domain","description","Glimmer","props","Object","assign","style","animationDelay","String","index","LinkPreview","fallback","Fragment","height","width"],"sources":["LinkPreview.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 \"./LinkPreview.css\";\n\nimport * as React from \"react\";\nimport type { CSSProperties } from \"react\";\nimport { Suspense } from \"react\";\n\ntype Preview = {\n title: string;\n description: string;\n img: string;\n domain: string;\n} | null;\n\n// Cached responses or running request promises\nconst PREVIEW_CACHE: Record<string, Promise<Preview> | { preview: Preview }> = {};\n\nconst URL_MATCHER =\n /((https?:\\/\\/(www\\.)?)|(www\\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;\n\nfunction useSuspenseRequest(url: string) {\n let cached = PREVIEW_CACHE[url];\n\n if (!url.match(URL_MATCHER)) {\n return { preview: null };\n }\n\n if (!cached) {\n cached = PREVIEW_CACHE[url] = fetch(`/api/link-preview?url=${encodeURI(url)}`)\n .then(response => response.json())\n .then(preview => {\n PREVIEW_CACHE[url] = preview;\n return preview;\n })\n .catch(() => {\n PREVIEW_CACHE[url] = { preview: null };\n });\n }\n\n if (cached instanceof Promise) {\n throw cached;\n }\n\n return cached;\n}\n\nfunction LinkPreviewContent({\n url\n}: Readonly<{\n url: string;\n}>): JSX.Element | null {\n const { preview } = useSuspenseRequest(url);\n if (preview === null) {\n return null;\n }\n return (\n <div className=\"CustomLinkPreview__container\">\n {preview.img && (\n <div className=\"CustomLinkPreview__imageWrapper\">\n <img\n src={preview.img}\n alt={preview.title}\n className=\"CustomLinkPreview__image\"\n />\n </div>\n )}\n {preview.domain && <div className=\"CustomLinkPreview__domain\">{preview.domain}</div>}\n {preview.title && <div className=\"CustomLinkPreview__title\">{preview.title}</div>}\n {preview.description && (\n <div className=\"CustomLinkPreview__description\">{preview.description}</div>\n )}\n </div>\n );\n}\n\nfunction Glimmer(props: { style: CSSProperties; index: number }): JSX.Element {\n return (\n <div\n className=\"CustomLinkPreview__glimmer\"\n {...props}\n style={{\n animationDelay: String((props.index || 0) * 300),\n ...(props.style || {})\n }}\n />\n );\n}\n\nexport function LinkPreview({\n url\n}: Readonly<{\n url: string;\n}>): JSX.Element {\n return (\n <Suspense\n fallback={\n <>\n <Glimmer style={{ height: \"80px\" }} index={0} />\n <Glimmer style={{ width: \"60%\" }} index={1} />\n <Glimmer style={{ width: \"80%\" }} index={2} />\n </>\n }\n >\n <LinkPreviewContent url={url} />\n </Suspense>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,QAAQ,QAAQ,OAAO;AAShC;AACA,MAAMC,aAAsE,GAAG,CAAC,CAAC;AAEjF,MAAMC,WAAW,GACb,iHAAiH;AAErH,SAASC,kBAAkBA,CAACC,GAAW,EAAE;EACrC,IAAIC,MAAM,GAAGJ,aAAa,CAACG,GAAG,CAAC;EAE/B,IAAI,CAACA,GAAG,CAACE,KAAK,CAACJ,WAAW,CAAC,EAAE;IACzB,OAAO;MAAEK,OAAO,EAAE;IAAK,CAAC;EAC5B;EAEA,IAAI,CAACF,MAAM,EAAE;IACTA,MAAM,GAAGJ,aAAa,CAACG,GAAG,CAAC,GAAGI,KAAK,CAAC,yBAAyBC,SAAS,CAACL,GAAG,CAAC,EAAE,CAAC,CACzEM,IAAI,CAACC,QAAQ,IAAIA,QAAQ,CAACC,IAAI,CAAC,CAAC,CAAC,CACjCF,IAAI,CAACH,OAAO,IAAI;MACbN,aAAa,CAACG,GAAG,CAAC,GAAGG,OAAO;MAC5B,OAAOA,OAAO;IAClB,CAAC,CAAC,CACDM,KAAK,CAAC,MAAM;MACTZ,aAAa,CAACG,GAAG,CAAC,GAA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,KAAK,CAACG,KAAK,IAAI,CAAC,CAAC;IACzB;EAAE,EACL,CAAC;AAEV;AAEA,OAAO,SAASI,WAAWA,CAAC;EACxB5B;AAGH,CAAC,EAAe;EACb,oBACIL,KAAA,CAAAiB,aAAA,CAAChB,QAAQ;IACLiC,QAAQ,eACJlC,KAAA,CAAAiB,aAAA,CAAAjB,KAAA,CAAAmC,QAAA,qBACInC,KAAA,CAAAiB,aAAA,CAACQ,OAAO;MAACI,KAAK,EAAE;QAAEO,MAAM,EAAE;MAAO,CAAE;MAACJ,KAAK,EAAE;IAAE,CAAE,CAAC,eAChDhC,KAAA,CAAAiB,aAAA,CAACQ,OAAO;MAACI,KAAK,EAAE;QAAEQ,KAAK,EAAE;MAAM,CAAE;MAACL,KAAK,EAAE;IAAE,CAAE,CAAC,eAC9ChC,KAAA,CAAAiB,aAAA,CAACQ,OAAO;MAACI,KAAK,EAAE;QAAEQ,KAAK,EAAE;MAAM,CAAE;MAACL,KAAK,EAAE;IAAE,CAAE,CAC/C;EACL,gBAEDhC,KAAA,CAAAiB,aAAA,CAACD,kBAAkB;IAACX,GAAG,EAAEA;EAAI,CAAE,CACzB,CAAC;AAEnB","ignoreList":[]}
|
package/ui/Placeholder.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import "./Placeholder.css";
|
|
9
9
|
import * as React from "react";
|
|
10
|
-
import { ReactNode } from "react";
|
|
10
|
+
import type { ReactNode } from "react";
|
|
11
11
|
export declare function Placeholder({ children, className, styles }: {
|
|
12
12
|
children: ReactNode;
|
|
13
13
|
className?: string;
|
package/ui/Placeholder.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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.Placeholder = Placeholder;
|
|
9
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
-
require("./Placeholder.css");
|
|
11
|
-
var React = _interopRequireWildcard(require("react"));
|
|
12
1
|
/**
|
|
13
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
3
|
*
|
|
@@ -17,12 +6,17 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
17
6
|
*
|
|
18
7
|
*/
|
|
19
8
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
import "./Placeholder.css";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
export function Placeholder({
|
|
12
|
+
children,
|
|
13
|
+
className,
|
|
14
|
+
styles
|
|
15
|
+
}) {
|
|
24
16
|
return /*#__PURE__*/React.createElement("div", {
|
|
25
|
-
style:
|
|
17
|
+
style: {
|
|
18
|
+
...styles
|
|
19
|
+
},
|
|
26
20
|
className: className || "Placeholder__root"
|
|
27
21
|
}, children);
|
|
28
22
|
}
|
package/ui/Placeholder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","Placeholder","children","className","styles","createElement","style"],"sources":["Placeholder.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 \"./Placeholder.css\";\n\nimport * as React from \"react\";\nimport type { ReactNode } from \"react\";\n\nexport function Placeholder({\n children,\n className,\n styles\n}: {\n children: ReactNode;\n className?: string;\n styles?: React.CSSProperties;\n}): JSX.Element {\n return (\n <div style={{ ...styles }} className={className || \"Placeholder__root\"}>\n {children}\n </div>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B,OAAO,SAASC,WAAWA,CAAC;EACxBC,QAAQ;EACRC,SAAS;EACTC;AAKJ,CAAC,EAAe;EACZ,oBACIJ,KAAA,CAAAK,aAAA;IAAKC,KAAK,EAAE;MAAE,GAAGF;IAAO,CAAE;IAACD,SAAS,EAAEA,SAAS,IAAI;EAAoB,GAClED,QACA,CAAC;AAEd","ignoreList":[]}
|
package/ui/TextInput.d.ts
CHANGED
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="react" />
|
|
9
8
|
import "./Input.css";
|
|
10
|
-
|
|
9
|
+
type Props = Readonly<{
|
|
11
10
|
"data-test-id"?: string;
|
|
12
11
|
label: string;
|
|
13
12
|
onChange: (val: string) => void;
|