onchain-lexical-ui 0.0.1 → 0.0.3
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/package.json +2 -2
- package/src/ContentEditable.module.less +7 -3
- package/src/DropDown.module.less +24 -7
- package/src/DropDown.tsx +64 -9
- package/src/DropdownColorPicker.tsx +14 -1
- package/src/EditorShellStyles/index.module.less +389 -5
- package/src/EditorShellStyles/index.tsx +3 -1
- package/src/Icon/index.tsx +27 -2
- package/src/images/icons/3-columns.svg +3 -0
- package/src/images/icons/LICENSE.md +5 -0
- package/src/images/icons/add-sign.svg +3 -0
- package/src/images/icons/arrow-clockwise.svg +1 -0
- package/src/images/icons/arrow-counterclockwise.svg +1 -0
- package/src/images/icons/bg-color.svg +1 -0
- package/src/images/icons/camera.svg +1 -0
- package/src/images/icons/card-checklist.svg +1 -0
- package/src/images/icons/caret-right-fill.svg +1 -0
- package/src/images/icons/chat-left-text.svg +1 -0
- package/src/images/icons/chat-right-dots.svg +1 -0
- package/src/images/icons/chat-right-text.svg +1 -0
- package/src/images/icons/chat-right.svg +1 -0
- package/src/images/icons/chat-square-quote.svg +1 -0
- package/src/images/icons/chevron-down.svg +1 -0
- package/src/images/icons/clipboard.svg +1 -0
- package/src/images/icons/close.svg +1 -0
- package/src/images/icons/code.svg +1 -0
- package/src/images/icons/comments.svg +1 -0
- package/src/images/icons/copy.svg +1 -0
- package/src/images/icons/diagram-2.svg +1 -0
- package/src/images/icons/download.svg +1 -0
- package/src/images/icons/draggable-block-menu.svg +1 -0
- package/src/images/icons/dropdown-more.svg +1 -0
- package/src/images/icons/figma.svg +1 -0
- package/src/images/icons/file-earmark-text.svg +4 -0
- package/src/images/icons/file-image.svg +1 -0
- package/src/images/icons/filetype-gif.svg +1 -0
- package/src/images/icons/font-color.svg +1 -0
- package/src/images/icons/font-family.svg +1 -0
- package/src/images/icons/gear.svg +1 -0
- package/src/images/icons/highlighter.svg +1 -0
- package/src/images/icons/horizontal-rule.svg +1 -0
- package/src/images/icons/indent.svg +1 -0
- package/src/images/icons/journal-code.svg +1 -0
- package/src/images/icons/journal-text.svg +1 -0
- package/src/images/icons/justify.svg +1 -0
- package/src/images/icons/link.svg +1 -0
- package/src/images/icons/list-ol.svg +1 -0
- package/src/images/icons/list-ul.svg +1 -0
- package/src/images/icons/lock-fill.svg +1 -0
- package/src/images/icons/lock.svg +1 -0
- package/src/images/icons/markdown.svg +1 -0
- package/src/images/icons/mic.svg +1 -0
- package/src/images/icons/minus-sign.svg +3 -0
- package/src/images/icons/outdent.svg +1 -0
- package/src/images/icons/paint-bucket.svg +1 -0
- package/src/images/icons/palette.svg +1 -0
- package/src/images/icons/pencil-fill.svg +1 -0
- package/src/images/icons/plug-fill.svg +1 -0
- package/src/images/icons/plug.svg +1 -0
- package/src/images/icons/plus-slash-minus.svg +1 -0
- package/src/images/icons/plus.svg +1 -0
- package/src/images/icons/prettier-error.svg +1 -0
- package/src/images/icons/prettier.svg +1 -0
- package/src/images/icons/scissors.svg +3 -0
- package/src/images/icons/send.svg +1 -0
- package/src/images/icons/square-check.svg +1 -0
- package/src/images/icons/sticky.svg +1 -0
- package/src/images/icons/success-alt.svg +1 -0
- package/src/images/icons/success.svg +1 -0
- package/src/images/icons/table.svg +1 -0
- package/src/images/icons/text-center.svg +1 -0
- package/src/images/icons/text-left.svg +1 -0
- package/src/images/icons/text-paragraph.svg +1 -0
- package/src/images/icons/text-right.svg +1 -0
- package/src/images/icons/trash.svg +1 -0
- package/src/images/icons/trash3.svg +1 -0
- package/src/images/icons/type-bold.svg +1 -0
- package/src/images/icons/type-capitalize.svg +1 -0
- package/src/images/icons/type-h1.svg +1 -0
- package/src/images/icons/type-h2.svg +1 -0
- package/src/images/icons/type-h3.svg +1 -0
- package/src/images/icons/type-h4.svg +1 -0
- package/src/images/icons/type-h5.svg +1 -0
- package/src/images/icons/type-h6.svg +1 -0
- package/src/images/icons/type-italic.svg +1 -0
- package/src/images/icons/type-lowercase.svg +3 -0
- package/src/images/icons/type-strikethrough.svg +1 -0
- package/src/images/icons/type-subscript.svg +1 -0
- package/src/images/icons/type-superscript.svg +1 -0
- package/src/images/icons/type-underline.svg +1 -0
- package/src/images/icons/type-uppercase.svg +3 -0
- package/src/images/icons/upload.svg +1 -0
- package/src/images/icons/user.svg +1 -0
- package/src/images/icons/vertical-bottom.svg +1 -0
- package/src/images/icons/vertical-middle.svg +1 -0
- package/src/images/icons/vertical-top.svg +1 -0
- package/src/images/icons/x.svg +1 -0
- package/src/images/icons/youtube.svg +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onchain-lexical-ui",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@ant-design/icons": "^6.0.0",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@lexical/utils": "^0.30.0",
|
|
11
11
|
"katex": "^0.16.22",
|
|
12
12
|
"lexical": "0.30.0",
|
|
13
|
-
"onchain-lexical-context": "^0.0.
|
|
13
|
+
"onchain-lexical-context": "^0.0.3",
|
|
14
14
|
"react-draggable": "^4.5.0"
|
|
15
15
|
},
|
|
16
16
|
"browser": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
.ContentEditable__root {
|
|
10
10
|
border: 0;
|
|
11
|
-
font-size:
|
|
11
|
+
font-size: 12px;
|
|
12
12
|
display: block;
|
|
13
13
|
position: relative;
|
|
14
14
|
outline: 0;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
background-color: #f9f9f9;
|
|
20
20
|
border-left: 26px solid #e6e6e6;
|
|
21
21
|
padding: 0 10px;
|
|
22
|
-
|
|
22
|
+
padding-bottom: 6px;
|
|
23
23
|
> [number='true'] {
|
|
24
24
|
left: 10px;
|
|
25
25
|
}
|
|
@@ -29,8 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
& [instance='true'] {
|
|
32
|
-
border-top:
|
|
32
|
+
border-top: 12px solid transparent;
|
|
33
33
|
&::before {
|
|
34
|
+
pointer-events: none;
|
|
34
35
|
content: '';
|
|
35
36
|
display: block;
|
|
36
37
|
background-color: #fff;
|
|
@@ -47,6 +48,9 @@
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
}
|
|
51
|
+
&:not(:nth-of-type(1)) {
|
|
52
|
+
margin-top: 6px;
|
|
53
|
+
}
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
/* @media (max-width: 1025px) {
|
package/src/DropDown.module.less
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
.arrow {
|
|
2
|
+
position: relative;
|
|
3
|
+
&::before {
|
|
4
|
+
content: '';
|
|
5
|
+
display: block;
|
|
6
|
+
width: 8px;
|
|
7
|
+
height: 8px;
|
|
8
|
+
position: absolute;
|
|
9
|
+
top: -2px;
|
|
10
|
+
left: 4px;
|
|
11
|
+
background-color: #fff;
|
|
12
|
+
z-index: -1;
|
|
13
|
+
transform: rotate(45deg);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
.dropdown {
|
|
2
18
|
z-index: 100;
|
|
3
19
|
display: block;
|
|
@@ -7,13 +23,13 @@
|
|
|
7
23
|
0 2px 4px 0 rgba(0, 0, 0, 0.1),
|
|
8
24
|
inset 0 0 0 1px rgba(255, 255, 255, 0.5);
|
|
9
25
|
// border-radius: 8px;
|
|
10
|
-
min-height: 40px;
|
|
26
|
+
// min-height: 40px;
|
|
11
27
|
background-color: #fff;
|
|
12
28
|
z-index: 1000;
|
|
13
29
|
:global {
|
|
14
30
|
.item {
|
|
15
|
-
margin: 0
|
|
16
|
-
padding:
|
|
31
|
+
margin: 0 6px 0 6px;
|
|
32
|
+
padding: 6px;
|
|
17
33
|
color: #050505;
|
|
18
34
|
cursor: pointer;
|
|
19
35
|
line-height: 16px;
|
|
@@ -25,15 +41,16 @@
|
|
|
25
41
|
justify-content: space-between;
|
|
26
42
|
background-color: #fff;
|
|
27
43
|
// border-radius: 8px;
|
|
44
|
+
font-size: 14px;
|
|
28
45
|
border: 0;
|
|
29
46
|
max-width: 250px;
|
|
30
47
|
min-width: 100px;
|
|
31
48
|
&:first-child {
|
|
32
|
-
margin-top:
|
|
49
|
+
margin-top: 6px;
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
&:last-child {
|
|
36
|
-
margin-bottom:
|
|
53
|
+
margin-bottom: 6px;
|
|
37
54
|
}
|
|
38
55
|
|
|
39
56
|
&:hover {
|
|
@@ -74,8 +91,8 @@
|
|
|
74
91
|
|
|
75
92
|
.icon {
|
|
76
93
|
display: flex;
|
|
77
|
-
width:
|
|
78
|
-
height:
|
|
94
|
+
width: 18px;
|
|
95
|
+
height: 18px;
|
|
79
96
|
user-select: none;
|
|
80
97
|
margin-right: 12px;
|
|
81
98
|
line-height: 16px;
|
package/src/DropDown.tsx
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type {JSX} from 'react';
|
|
10
10
|
|
|
11
11
|
import {isDOMNode} from 'lexical';
|
|
12
|
+
import {useSettings} from 'onchain-lexical-context/settings';
|
|
12
13
|
import * as React from 'react';
|
|
13
14
|
import {
|
|
14
15
|
ReactNode,
|
|
@@ -37,7 +38,7 @@ export function DropDownItem({
|
|
|
37
38
|
title,
|
|
38
39
|
}: {
|
|
39
40
|
children: React.ReactNode;
|
|
40
|
-
className
|
|
41
|
+
className?: string;
|
|
41
42
|
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
42
43
|
title?: string;
|
|
43
44
|
}) {
|
|
@@ -59,7 +60,7 @@ export function DropDownItem({
|
|
|
59
60
|
|
|
60
61
|
return (
|
|
61
62
|
<button
|
|
62
|
-
className={className}
|
|
63
|
+
className={className ?? 'item'}
|
|
63
64
|
onClick={onClick}
|
|
64
65
|
ref={ref}
|
|
65
66
|
title={title}
|
|
@@ -72,10 +73,16 @@ export function DropDownItem({
|
|
|
72
73
|
function DropDownItems({
|
|
73
74
|
children,
|
|
74
75
|
dropDownRef,
|
|
76
|
+
arrow = false,
|
|
77
|
+
zIndex = 100,
|
|
78
|
+
arrowX,
|
|
75
79
|
onClose,
|
|
76
80
|
}: {
|
|
77
81
|
children: React.ReactNode;
|
|
78
82
|
dropDownRef: React.Ref<HTMLDivElement>;
|
|
83
|
+
zIndex?: number;
|
|
84
|
+
arrow?: boolean;
|
|
85
|
+
arrowX?: number;
|
|
79
86
|
onClose: () => void;
|
|
80
87
|
}) {
|
|
81
88
|
const [items, setItems] = useState<React.RefObject<HTMLButtonElement>[]>();
|
|
@@ -140,8 +147,9 @@ function DropDownItems({
|
|
|
140
147
|
return (
|
|
141
148
|
<DropDownContext.Provider value={contextValue}>
|
|
142
149
|
<div
|
|
143
|
-
className={`${Styles.dropdown}`}
|
|
150
|
+
className={`${Styles.dropdown} ${arrow ? Styles.arrow : ''}`}
|
|
144
151
|
ref={dropDownRef}
|
|
152
|
+
style={{left: arrowX, zIndex}}
|
|
145
153
|
onKeyDown={handleKeyDown}>
|
|
146
154
|
{children}
|
|
147
155
|
</div>
|
|
@@ -151,24 +159,34 @@ function DropDownItems({
|
|
|
151
159
|
|
|
152
160
|
export default function DropDown({
|
|
153
161
|
disabled = false,
|
|
162
|
+
showIcon = true,
|
|
163
|
+
arrow = false,
|
|
164
|
+
arrowX,
|
|
154
165
|
buttonLabel,
|
|
155
166
|
buttonAriaLabel,
|
|
156
167
|
buttonClassName,
|
|
157
168
|
buttonIconClassName,
|
|
158
169
|
children,
|
|
159
170
|
stopCloseOnClickSelf,
|
|
171
|
+
onOpen,
|
|
160
172
|
}: {
|
|
161
173
|
disabled?: boolean;
|
|
162
174
|
buttonAriaLabel?: string;
|
|
163
|
-
buttonClassName
|
|
175
|
+
buttonClassName?: string;
|
|
164
176
|
buttonIconClassName?: string;
|
|
165
|
-
buttonLabel?:
|
|
177
|
+
buttonLabel?: React.ReactNode;
|
|
178
|
+
showIcon?: boolean;
|
|
166
179
|
children: ReactNode;
|
|
167
180
|
stopCloseOnClickSelf?: boolean;
|
|
181
|
+
arrow?: boolean;
|
|
182
|
+
arrowX?: number;
|
|
183
|
+
onOpen?: (value: boolean) => void;
|
|
168
184
|
}): JSX.Element {
|
|
169
185
|
const dropDownRef = useRef<HTMLDivElement>(null);
|
|
170
186
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
171
187
|
const [showDropDown, setShowDropDown] = useState(false);
|
|
188
|
+
const {extra} = useSettings();
|
|
189
|
+
const [zIndex, setZIndex] = useState(100);
|
|
172
190
|
|
|
173
191
|
const handleClose = () => {
|
|
174
192
|
setShowDropDown(false);
|
|
@@ -177,6 +195,18 @@ export default function DropDown({
|
|
|
177
195
|
}
|
|
178
196
|
};
|
|
179
197
|
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
if (showDropDown) {
|
|
200
|
+
if (extra.getZIndex) {
|
|
201
|
+
setZIndex(extra.getZIndex());
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
if (extra.reduceZIndex) {
|
|
205
|
+
extra.reduceZIndex();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}, [showDropDown]);
|
|
209
|
+
|
|
180
210
|
useEffect(() => {
|
|
181
211
|
const button = buttonRef.current;
|
|
182
212
|
const dropDown = dropDownRef.current;
|
|
@@ -239,25 +269,50 @@ export default function DropDown({
|
|
|
239
269
|
};
|
|
240
270
|
}, [buttonRef, dropDownRef, showDropDown]);
|
|
241
271
|
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
const wheel = (e: WheelEvent) => {
|
|
274
|
+
if (e.target instanceof HTMLElement) {
|
|
275
|
+
if (!e.target.closest(`.${Styles.dropdown}`)) {
|
|
276
|
+
setShowDropDown(false);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
window.addEventListener('wheel', wheel);
|
|
281
|
+
return () => {
|
|
282
|
+
window.removeEventListener('wheel', wheel);
|
|
283
|
+
};
|
|
284
|
+
}, []);
|
|
285
|
+
|
|
286
|
+
useEffect(() => {
|
|
287
|
+
if (onOpen) {
|
|
288
|
+
onOpen(showDropDown);
|
|
289
|
+
}
|
|
290
|
+
}, [showDropDown]);
|
|
291
|
+
|
|
242
292
|
return (
|
|
243
293
|
<>
|
|
244
294
|
<button
|
|
245
295
|
type="button"
|
|
246
296
|
disabled={disabled}
|
|
247
|
-
aria-label={buttonAriaLabel
|
|
248
|
-
className={buttonClassName}
|
|
297
|
+
aria-label={buttonAriaLabel}
|
|
298
|
+
className={buttonClassName ?? 'down'}
|
|
249
299
|
onClick={() => setShowDropDown(!showDropDown)}
|
|
250
300
|
ref={buttonRef}>
|
|
251
301
|
{buttonIconClassName && <span className={buttonIconClassName} />}
|
|
252
302
|
{buttonLabel && (
|
|
253
303
|
<span className="text dropdown-button-text">{buttonLabel}</span>
|
|
254
304
|
)}
|
|
255
|
-
<i className="chevron-down" />
|
|
305
|
+
{showIcon ? <i className="chevron-down" /> : null}
|
|
256
306
|
</button>
|
|
257
307
|
|
|
258
308
|
{showDropDown &&
|
|
259
309
|
createPortal(
|
|
260
|
-
<DropDownItems
|
|
310
|
+
<DropDownItems
|
|
311
|
+
dropDownRef={dropDownRef}
|
|
312
|
+
zIndex={zIndex}
|
|
313
|
+
arrow={arrow}
|
|
314
|
+
arrowX={arrowX}
|
|
315
|
+
onClose={handleClose}>
|
|
261
316
|
{children}
|
|
262
317
|
</DropDownItems>,
|
|
263
318
|
document.body,
|
|
@@ -30,12 +30,25 @@ export default function DropdownColorPicker({
|
|
|
30
30
|
onChange,
|
|
31
31
|
...rest
|
|
32
32
|
}: Props) {
|
|
33
|
+
const timeout = React.useRef(0);
|
|
34
|
+
const debounce = React.useCallback(
|
|
35
|
+
(value: string, skipHistoryStack: boolean) => {
|
|
36
|
+
clearTimeout(timeout.current);
|
|
37
|
+
timeout.current = window.setTimeout(() => {
|
|
38
|
+
if (onChange) {
|
|
39
|
+
onChange(value, skipHistoryStack);
|
|
40
|
+
}
|
|
41
|
+
}, 100);
|
|
42
|
+
},
|
|
43
|
+
[onChange],
|
|
44
|
+
);
|
|
45
|
+
|
|
33
46
|
return (
|
|
34
47
|
<DropDown
|
|
35
48
|
{...rest}
|
|
36
49
|
disabled={disabled}
|
|
37
50
|
stopCloseOnClickSelf={stopCloseOnClickSelf}>
|
|
38
|
-
<ColorPicker color={color} onChange={
|
|
51
|
+
<ColorPicker color={color} onChange={debounce} />
|
|
39
52
|
</DropDown>
|
|
40
53
|
);
|
|
41
54
|
}
|