@webiny/lexical-nodes 6.3.0 → 6.4.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.
- package/FontColorNode.js +94 -119
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.js +160 -183
- package/HeadingNode.js.map +1 -1
- package/ImageNode.js +101 -131
- package/ImageNode.js.map +1 -1
- package/LinkNode.js +228 -315
- package/LinkNode.js.map +1 -1
- package/ListItemNode.js +249 -320
- package/ListItemNode.js.map +1 -1
- package/ListNode.js +174 -223
- package/ListNode.js.map +1 -1
- package/ParagraphNode.js +119 -148
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.js +97 -102
- package/QuoteNode.js.map +1 -1
- package/components/ImageNode/ImageComponent.js +117 -147
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.js +167 -194
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.js +20 -23
- package/generateInitialLexicalValue.js.map +1 -1
- package/index.js +38 -26
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/prepareLexicalState.js +30 -43
- package/prepareLexicalState.js.map +1 -1
- package/types.js +0 -3
- package/utils/clearNodeFormating.js +14 -15
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.js +277 -368
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.js +6 -13
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.js +6 -7
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.js +6 -13
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.js +6 -11
- package/utils/getStyleId.js.map +1 -1
- package/utils/listNode.js +60 -84
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.js +67 -118
- package/utils/toggleLink.js.map +1 -1
- package/types.js.map +0 -1
|
@@ -1,201 +1,174 @@
|
|
|
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
|
-
import * as React from "react";
|
|
10
|
-
import { useRef } from "react";
|
|
1
|
+
import * as __rspack_external_react from "react";
|
|
11
2
|
function clamp(value, min, max) {
|
|
12
|
-
|
|
3
|
+
return Math.min(Math.max(value, min), max);
|
|
13
4
|
}
|
|
14
5
|
const Direction = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
east: 1,
|
|
7
|
+
north: 8,
|
|
8
|
+
south: 2,
|
|
9
|
+
west: 4
|
|
19
10
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
image
|
|
117
|
-
positioning
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
onPointerDown: event => {
|
|
181
|
-
handlePointerDown(event, Direction.south);
|
|
182
|
-
}
|
|
183
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
184
|
-
className: "image-resizer image-resizer-sw",
|
|
185
|
-
onPointerDown: event => {
|
|
186
|
-
handlePointerDown(event, Direction.south | Direction.west);
|
|
187
|
-
}
|
|
188
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
189
|
-
className: "image-resizer image-resizer-w",
|
|
190
|
-
onPointerDown: event => {
|
|
191
|
-
handlePointerDown(event, Direction.west);
|
|
192
|
-
}
|
|
193
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
194
|
-
className: "image-resizer image-resizer-nw",
|
|
195
|
-
onPointerDown: event => {
|
|
196
|
-
handlePointerDown(event, Direction.north | Direction.west);
|
|
197
|
-
}
|
|
198
|
-
}));
|
|
11
|
+
function ImageResizer({ onResizeStart, onResizeEnd, imageRef, maxWidth, editor }) {
|
|
12
|
+
const controlWrapperRef = (0, __rspack_external_react.useRef)(null);
|
|
13
|
+
const userSelect = (0, __rspack_external_react.useRef)({
|
|
14
|
+
priority: "",
|
|
15
|
+
value: "default"
|
|
16
|
+
});
|
|
17
|
+
const positioningRef = (0, __rspack_external_react.useRef)({
|
|
18
|
+
currentHeight: 0,
|
|
19
|
+
currentWidth: 0,
|
|
20
|
+
direction: 0,
|
|
21
|
+
isResizing: false,
|
|
22
|
+
ratio: 0,
|
|
23
|
+
startHeight: 0,
|
|
24
|
+
startWidth: 0,
|
|
25
|
+
startX: 0,
|
|
26
|
+
startY: 0
|
|
27
|
+
});
|
|
28
|
+
const editorRootElement = editor.getRootElement();
|
|
29
|
+
const maxWidthContainer = maxWidth ? maxWidth : null !== editorRootElement ? editorRootElement.getBoundingClientRect().width - 20 : 100;
|
|
30
|
+
const maxHeightContainer = null !== editorRootElement ? editorRootElement.getBoundingClientRect().height - 20 : 100;
|
|
31
|
+
const minWidth = 100;
|
|
32
|
+
const minHeight = 100;
|
|
33
|
+
const setStartCursor = (direction)=>{
|
|
34
|
+
const ew = direction === Direction.east || direction === Direction.west;
|
|
35
|
+
const ns = direction === Direction.north || direction === Direction.south;
|
|
36
|
+
const nwse = direction & Direction.north && direction & Direction.west || direction & Direction.south && direction & Direction.east;
|
|
37
|
+
const cursorDir = ew ? "ew" : ns ? "ns" : nwse ? "nwse" : "nesw";
|
|
38
|
+
if (null !== editorRootElement) editorRootElement.style.setProperty("cursor", `${cursorDir}-resize`, "important");
|
|
39
|
+
if (null !== document.body) {
|
|
40
|
+
document.body.style.setProperty("cursor", `${cursorDir}-resize`, "important");
|
|
41
|
+
userSelect.current.value = document.body.style.getPropertyValue("-webkit-user-select");
|
|
42
|
+
userSelect.current.priority = document.body.style.getPropertyPriority("-webkit-user-select");
|
|
43
|
+
document.body.style.setProperty("-webkit-user-select", "none", "important");
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const setEndCursor = ()=>{
|
|
47
|
+
if (null !== editorRootElement) editorRootElement.style.setProperty("cursor", "text");
|
|
48
|
+
if (null !== document.body) {
|
|
49
|
+
document.body.style.setProperty("cursor", "default");
|
|
50
|
+
document.body.style.setProperty("-webkit-user-select", userSelect.current.value, userSelect.current.priority);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const handlePointerDown = (event, direction)=>{
|
|
54
|
+
if (!editor.isEditable()) return;
|
|
55
|
+
const image = imageRef.current;
|
|
56
|
+
const controlWrapper = controlWrapperRef.current;
|
|
57
|
+
if (null !== image && null !== controlWrapper) {
|
|
58
|
+
const { width, height } = image.getBoundingClientRect();
|
|
59
|
+
const positioning = positioningRef.current;
|
|
60
|
+
positioning.startWidth = width;
|
|
61
|
+
positioning.startHeight = height;
|
|
62
|
+
positioning.ratio = width / height;
|
|
63
|
+
positioning.currentWidth = width;
|
|
64
|
+
positioning.currentHeight = height;
|
|
65
|
+
positioning.startX = event.clientX;
|
|
66
|
+
positioning.startY = event.clientY;
|
|
67
|
+
positioning.isResizing = true;
|
|
68
|
+
positioning.direction = direction;
|
|
69
|
+
setStartCursor(direction);
|
|
70
|
+
onResizeStart();
|
|
71
|
+
controlWrapper.classList.add("image-control-wrapper--resizing");
|
|
72
|
+
image.style.height = `${height}px`;
|
|
73
|
+
image.style.width = `${width}px`;
|
|
74
|
+
document.addEventListener("pointermove", handlePointerMove);
|
|
75
|
+
document.addEventListener("pointerup", handlePointerUp);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const handlePointerMove = (event)=>{
|
|
79
|
+
const image = imageRef.current;
|
|
80
|
+
const positioning = positioningRef.current;
|
|
81
|
+
const isHorizontal = positioning.direction & (Direction.east | Direction.west);
|
|
82
|
+
const isVertical = positioning.direction & (Direction.south | Direction.north);
|
|
83
|
+
if (null !== image && positioning.isResizing) if (isHorizontal && isVertical) {
|
|
84
|
+
let diff = Math.floor(positioning.startX - event.clientX);
|
|
85
|
+
diff = positioning.direction & Direction.east ? -diff : diff;
|
|
86
|
+
const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
|
|
87
|
+
const height = width / positioning.ratio;
|
|
88
|
+
image.style.width = `${width}px`;
|
|
89
|
+
image.style.height = `${height}px`;
|
|
90
|
+
positioning.currentHeight = height;
|
|
91
|
+
positioning.currentWidth = width;
|
|
92
|
+
} else if (isVertical) {
|
|
93
|
+
let diff = Math.floor(positioning.startY - event.clientY);
|
|
94
|
+
diff = positioning.direction & Direction.south ? -diff : diff;
|
|
95
|
+
const height = clamp(positioning.startHeight + diff, minHeight, maxHeightContainer);
|
|
96
|
+
image.style.height = `${height}px`;
|
|
97
|
+
positioning.currentHeight = height;
|
|
98
|
+
} else {
|
|
99
|
+
let diff = Math.floor(positioning.startX - event.clientX);
|
|
100
|
+
diff = positioning.direction & Direction.east ? -diff : diff;
|
|
101
|
+
const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
|
|
102
|
+
image.style.width = `${width}px`;
|
|
103
|
+
positioning.currentWidth = width;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const handlePointerUp = ()=>{
|
|
107
|
+
const image = imageRef.current;
|
|
108
|
+
const positioning = positioningRef.current;
|
|
109
|
+
const controlWrapper = controlWrapperRef.current;
|
|
110
|
+
if (null !== image && null !== controlWrapper && positioning.isResizing) {
|
|
111
|
+
const width = positioning.currentWidth;
|
|
112
|
+
const height = positioning.currentHeight;
|
|
113
|
+
positioning.startWidth = 0;
|
|
114
|
+
positioning.startHeight = 0;
|
|
115
|
+
positioning.ratio = 0;
|
|
116
|
+
positioning.startX = 0;
|
|
117
|
+
positioning.startY = 0;
|
|
118
|
+
positioning.currentWidth = 0;
|
|
119
|
+
positioning.currentHeight = 0;
|
|
120
|
+
positioning.isResizing = false;
|
|
121
|
+
controlWrapper.classList.remove("image-control-wrapper--resizing");
|
|
122
|
+
setEndCursor();
|
|
123
|
+
onResizeEnd(width, height);
|
|
124
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
125
|
+
document.removeEventListener("pointerup", handlePointerUp);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
129
|
+
ref: controlWrapperRef
|
|
130
|
+
}, /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
131
|
+
className: "image-resizer image-resizer-n",
|
|
132
|
+
onPointerDown: (event)=>{
|
|
133
|
+
handlePointerDown(event, Direction.north);
|
|
134
|
+
}
|
|
135
|
+
}), /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
136
|
+
className: "image-resizer image-resizer-ne",
|
|
137
|
+
onPointerDown: (event)=>{
|
|
138
|
+
handlePointerDown(event, Direction.north | Direction.east);
|
|
139
|
+
}
|
|
140
|
+
}), /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
141
|
+
className: "image-resizer image-resizer-e",
|
|
142
|
+
onPointerDown: (event)=>{
|
|
143
|
+
handlePointerDown(event, Direction.east);
|
|
144
|
+
}
|
|
145
|
+
}), /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
146
|
+
className: "image-resizer image-resizer-se",
|
|
147
|
+
onPointerDown: (event)=>{
|
|
148
|
+
handlePointerDown(event, Direction.south | Direction.east);
|
|
149
|
+
}
|
|
150
|
+
}), /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
151
|
+
className: "image-resizer image-resizer-s",
|
|
152
|
+
onPointerDown: (event)=>{
|
|
153
|
+
handlePointerDown(event, Direction.south);
|
|
154
|
+
}
|
|
155
|
+
}), /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
156
|
+
className: "image-resizer image-resizer-sw",
|
|
157
|
+
onPointerDown: (event)=>{
|
|
158
|
+
handlePointerDown(event, Direction.south | Direction.west);
|
|
159
|
+
}
|
|
160
|
+
}), /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
161
|
+
className: "image-resizer image-resizer-w",
|
|
162
|
+
onPointerDown: (event)=>{
|
|
163
|
+
handlePointerDown(event, Direction.west);
|
|
164
|
+
}
|
|
165
|
+
}), /*#__PURE__*/ __rspack_external_react.createElement("div", {
|
|
166
|
+
className: "image-resizer image-resizer-nw",
|
|
167
|
+
onPointerDown: (event)=>{
|
|
168
|
+
handlePointerDown(event, Direction.north | Direction.west);
|
|
169
|
+
}
|
|
170
|
+
}));
|
|
199
171
|
}
|
|
172
|
+
export { ImageResizer };
|
|
200
173
|
|
|
201
174
|
//# sourceMappingURL=ImageResizer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useRef","clamp","value","min","max","Math","Direction","east","north","south","west","ImageResizer","onResizeStart","onResizeEnd","imageRef","maxWidth","editor","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","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 imageRef,\n maxWidth,\n editor\n}: {\n editor: LexicalEditor;\n imageRef: { current: null | HTMLElement };\n maxWidth?: number;\n onResizeEnd: (width: \"inherit\" | number, height: \"inherit\" | number) => void;\n onResizeStart: () => void;\n}): React.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 <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,QAAQ;EACRC,QAAQ;EACRC;AAOJ,CAAC,EAAqB;EAClB,MAAMC,iBAAiB,GAAGjB,MAAM,CAAiB,IAAI,CAAC;EACtD,MAAMkB,UAAU,GAAGlB,MAAM,CAAC;IACtBmB,QAAQ,EAAE,EAAE;IACZjB,KAAK,EAAE;EACX,CAAC,CAAC;EACF,MAAMkB,cAAc,GAAGpB,MAAM,CAU1B;IACCqB,aAAa,EAAE,CAAC;IAChBC,YAAY,EAAE,CAAC;IACfC,SAAS,EAAE,CAAC;IACZC,UAAU,EAAE,KAAK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CAAAwE,aAAA;IACIE,SAAS,EAAC,gCAAgC;IAC1CC,aAAa,EAAErB,KAAK,IAAI;MACpBD,iBAAiB,CAACC,KAAK,EAAE/C,SAAS,CAACG,KAAK,GAAGH,SAAS,CAACI,IAAI,CAAC;IAC9D;EAAE,CACL,CAAC,eACFX,KAAA,CAAAwE,aAAA;IACIE,SAAS,EAAC,+BAA+B;IACzCC,aAAa,EAAErB,KAAK,IAAI;MACpBD,iBAAiB,CAACC,KAAK,EAAE/C,SAAS,CAACI,IAAI,CAAC;IAC5C;EAAE,CACL,CAAC,eACFX,KAAA,CAAAwE,aAAA;IACIE,SAAS,EAAC,gCAAgC;IAC1CC,aAAa,EAAErB,KAAK,IAAI;MACpBD,iBAAiB,CAACC,KAAK,EAAE/C,SAAS,CAACE,KAAK,GAAGF,SAAS,CAACI,IAAI,CAAC;IAC9D;EAAE,CACL,CACA,CAAC;AAEd","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"components/ImageNode/ImageResizer.js","sources":["../../../src/components/ImageNode/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 imageRef,\n maxWidth,\n editor\n}: {\n editor: LexicalEditor;\n imageRef: { current: null | HTMLElement };\n maxWidth?: number;\n onResizeEnd: (width: \"inherit\" | number, height: \"inherit\" | number) => void;\n onResizeStart: () => void;\n}): React.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 <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"],"names":["clamp","value","min","max","Math","Direction","ImageResizer","onResizeStart","onResizeEnd","imageRef","maxWidth","editor","controlWrapperRef","useRef","userSelect","positioningRef","editorRootElement","maxWidthContainer","maxHeightContainer","minWidth","minHeight","setStartCursor","direction","ew","ns","nwse","cursorDir","document","setEndCursor","handlePointerDown","event","image","controlWrapper","width","height","positioning","handlePointerMove","handlePointerUp","isHorizontal","isVertical","diff"],"mappings":";AAaA,SAASA,MAAMC,KAAa,EAA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,sCAAC;QAAI,KAAKzB;qBACN,sCAAC;QACG,WAAU;QACV,eAAekB,CAAAA;YACXD,kBAAkBC,OAAOzB,UAAU,KAAK;QAC5C;sBAEJ,sCAAC;QACG,WAAU;QACV,eAAeyB,CAAAA;YACXD,kBAAkBC,OAAOzB,UAAU,KAAK,GAAGA,UAAU,IAAI;QAC7D;sBAEJ,sCAAC;QACG,WAAU;QACV,eAAeyB,CAAAA;YACXD,kBAAkBC,OAAOzB,UAAU,IAAI;QAC3C;sBAEJ,sCAAC;QACG,WAAU;QACV,eAAeyB,CAAAA;YACXD,kBAAkBC,OAAOzB,UAAU,KAAK,GAAGA,UAAU,IAAI;QAC7D;sBAEJ,sCAAC;QACG,WAAU;QACV,eAAeyB,CAAAA;YACXD,kBAAkBC,OAAOzB,UAAU,KAAK;QAC5C;sBAEJ,sCAAC;QACG,WAAU;QACV,eAAeyB,CAAAA;YACXD,kBAAkBC,OAAOzB,UAAU,KAAK,GAAGA,UAAU,IAAI;QAC7D;sBAEJ,sCAAC;QACG,WAAU;QACV,eAAeyB,CAAAA;YACXD,kBAAkBC,OAAOzB,UAAU,IAAI;QAC3C;sBAEJ,sCAAC;QACG,WAAU;QACV,eAAeyB,CAAAA;YACXD,kBAAkBC,OAAOzB,UAAU,KAAK,GAAGA,UAAU,IAAI;QAC7D;;AAIhB"}
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
const defaultLexicalValue = JSON.stringify({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
root: {
|
|
3
|
+
children: [
|
|
4
|
+
{
|
|
5
|
+
children: [],
|
|
6
|
+
direction: null,
|
|
7
|
+
format: "",
|
|
8
|
+
indent: 0,
|
|
9
|
+
styles: [],
|
|
10
|
+
type: "wby-paragraph",
|
|
11
|
+
version: 1
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
direction: null,
|
|
15
|
+
format: "",
|
|
16
|
+
indent: 0,
|
|
17
|
+
type: "root",
|
|
18
|
+
version: 1
|
|
19
|
+
}
|
|
18
20
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @description Basic JSON data string that will initialize the editor.
|
|
22
|
-
*/
|
|
23
|
-
export const generateInitialLexicalValue = () => {
|
|
24
|
-
return defaultLexicalValue;
|
|
25
|
-
};
|
|
21
|
+
const generateInitialLexicalValue = ()=>defaultLexicalValue;
|
|
22
|
+
export { generateInitialLexicalValue };
|
|
26
23
|
|
|
27
24
|
//# sourceMappingURL=generateInitialLexicalValue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"generateInitialLexicalValue.js","sources":["../src/generateInitialLexicalValue.ts"],"sourcesContent":["const defaultLexicalValue = JSON.stringify({\n root: {\n children: [\n {\n children: [],\n direction: null,\n format: \"\",\n indent: 0,\n styles: [],\n type: \"wby-paragraph\",\n version: 1\n }\n ],\n direction: null,\n format: \"\",\n indent: 0,\n type: \"root\",\n version: 1\n }\n});\n\n/**\n * @description Basic JSON data string that will initialize the editor.\n */\nexport const generateInitialLexicalValue = (): string => {\n return defaultLexicalValue;\n};\n"],"names":["defaultLexicalValue","JSON","generateInitialLexicalValue"],"mappings":"AAAA,MAAMA,sBAAsBC,KAAK,SAAS,CAAC;IACvC,MAAM;QACF,UAAU;YACN;gBACI,UAAU,EAAE;gBACZ,WAAW;gBACX,QAAQ;gBACR,QAAQ;gBACR,QAAQ,EAAE;gBACV,MAAM;gBACN,SAAS;YACb;SACH;QACD,WAAW;QACX,QAAQ;QACR,QAAQ;QACR,MAAM;QACN,SAAS;IACb;AACJ;AAKO,MAAMC,8BAA8B,IAChCF"}
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ParagraphNode
|
|
2
|
-
import { HeadingNode
|
|
1
|
+
import { ParagraphNode } from "lexical";
|
|
2
|
+
import { HeadingNode, QuoteNode } from "@lexical/rich-text";
|
|
3
3
|
import { CodeHighlightNode, CodeNode } from "@lexical/code";
|
|
4
4
|
import { HashtagNode } from "@lexical/hashtag";
|
|
5
5
|
import { MarkNode } from "@lexical/mark";
|
|
@@ -8,9 +8,9 @@ import { AutoLinkNode, LinkNode } from "./LinkNode.js";
|
|
|
8
8
|
import { FontColorNode } from "./FontColorNode.js";
|
|
9
9
|
import { ListNode } from "./ListNode.js";
|
|
10
10
|
import { ListItemNode } from "./ListItemNode.js";
|
|
11
|
-
import { HeadingNode } from "./HeadingNode.js";
|
|
12
|
-
import { ParagraphNode } from "./ParagraphNode.js";
|
|
13
|
-
import { QuoteNode } from "./QuoteNode.js";
|
|
11
|
+
import { HeadingNode as external_HeadingNode_js_HeadingNode } from "./HeadingNode.js";
|
|
12
|
+
import { ParagraphNode as external_ParagraphNode_js_ParagraphNode } from "./ParagraphNode.js";
|
|
13
|
+
import { QuoteNode as external_QuoteNode_js_QuoteNode } from "./QuoteNode.js";
|
|
14
14
|
import { ImageNode } from "./ImageNode.js";
|
|
15
15
|
export * from "./FontColorNode.js";
|
|
16
16
|
export * from "./ListNode.js";
|
|
@@ -29,26 +29,38 @@ export * from "./utils/clearNodeFormating.js";
|
|
|
29
29
|
export * from "./utils/toggleLink.js";
|
|
30
30
|
export * from "./prepareLexicalState.js";
|
|
31
31
|
export * from "./generateInitialLexicalValue.js";
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
32
|
+
const allNodes = [
|
|
33
|
+
external_ParagraphNode_js_ParagraphNode,
|
|
34
|
+
{
|
|
35
|
+
replace: ParagraphNode,
|
|
36
|
+
with: ()=>new external_ParagraphNode_js_ParagraphNode(),
|
|
37
|
+
withKlass: external_ParagraphNode_js_ParagraphNode
|
|
38
|
+
},
|
|
39
|
+
external_HeadingNode_js_HeadingNode,
|
|
40
|
+
{
|
|
41
|
+
replace: HeadingNode,
|
|
42
|
+
with: (node)=>new external_HeadingNode_js_HeadingNode(node.getTag()),
|
|
43
|
+
withKlass: external_HeadingNode_js_HeadingNode
|
|
44
|
+
},
|
|
45
|
+
external_QuoteNode_js_QuoteNode,
|
|
46
|
+
{
|
|
47
|
+
replace: QuoteNode,
|
|
48
|
+
with: ()=>new external_QuoteNode_js_QuoteNode(),
|
|
49
|
+
withKlass: external_QuoteNode_js_QuoteNode
|
|
50
|
+
},
|
|
51
|
+
ImageNode,
|
|
52
|
+
ListNode,
|
|
53
|
+
ListItemNode,
|
|
54
|
+
CodeNode,
|
|
55
|
+
HashtagNode,
|
|
56
|
+
CodeHighlightNode,
|
|
57
|
+
AutoLinkNode,
|
|
58
|
+
OverflowNode,
|
|
59
|
+
MarkNode,
|
|
60
|
+
FontColorNode,
|
|
61
|
+
external_QuoteNode_js_QuoteNode,
|
|
62
|
+
LinkNode
|
|
63
|
+
];
|
|
64
|
+
export { allNodes };
|
|
53
65
|
|
|
54
66
|
//# sourceMappingURL=index.js.map
|