@overlap/rte 0.1.4 → 0.1.5
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 +3 -8
- package/src/components/Dropdown.tsx +103 -0
- package/src/components/Editor.css +2 -0
- package/src/components/Editor.tsx +828 -0
- package/src/components/FloatingToolbar.tsx +214 -0
- package/src/components/IconWrapper.tsx +14 -0
- package/src/components/Icons.tsx +374 -0
- package/src/components/Toolbar.tsx +137 -0
- package/src/components/index.ts +3 -0
- package/src/index.ts +19 -0
- package/src/plugins/base.tsx +91 -0
- package/src/plugins/blockFormat.tsx +194 -0
- package/src/plugins/clearFormatting.tsx +31 -0
- package/src/plugins/colors.tsx +122 -0
- package/src/plugins/fontSize.tsx +81 -0
- package/src/plugins/headings.tsx +87 -0
- package/src/plugins/image.tsx +189 -0
- package/src/plugins/index.tsx +161 -0
- package/src/plugins/listIndent.tsx +90 -0
- package/src/plugins/optional.tsx +243 -0
- package/src/styles.css +638 -0
- package/src/types.ts +95 -0
- package/src/utils/clearFormatting.ts +244 -0
- package/src/utils/content.ts +290 -0
- package/src/utils/history.ts +59 -0
- package/src/utils/listIndent.ts +171 -0
- package/src/utils/stateReflection.ts +175 -0
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overlap/rte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A lightweight, extensible Rich Text Editor for React",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"src"
|
|
10
11
|
],
|
|
11
12
|
"type": "module",
|
|
12
13
|
"scripts": {
|
|
@@ -49,11 +50,5 @@
|
|
|
49
50
|
"rollup-plugin-dts": "^6.1.0",
|
|
50
51
|
"typescript": "^5.3.3"
|
|
51
52
|
},
|
|
52
|
-
"directories": {
|
|
53
|
-
"example": "example"
|
|
54
|
-
},
|
|
55
|
-
"bugs": {
|
|
56
|
-
"url": "https://github.com/overlap-dev/rte/issues"
|
|
57
|
-
},
|
|
58
53
|
"homepage": "https://github.com/overlap-dev/rte#readme"
|
|
59
54
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { Icon } from './Icons';
|
|
3
|
+
|
|
4
|
+
interface DropdownProps {
|
|
5
|
+
icon: string;
|
|
6
|
+
label: string;
|
|
7
|
+
options: Array<{ value: string; label: string; icon?: string; color?: string; preview?: string; headingPreview?: string }>;
|
|
8
|
+
onSelect: (value: string) => void;
|
|
9
|
+
currentValue?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Dropdown: React.FC<DropdownProps> = ({
|
|
14
|
+
icon,
|
|
15
|
+
label,
|
|
16
|
+
options,
|
|
17
|
+
onSelect,
|
|
18
|
+
currentValue,
|
|
19
|
+
disabled,
|
|
20
|
+
}) => {
|
|
21
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
22
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
26
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
|
|
27
|
+
setIsOpen(false);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (isOpen) {
|
|
32
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
37
|
+
};
|
|
38
|
+
}, [isOpen]);
|
|
39
|
+
|
|
40
|
+
const handleSelect = (value: string) => {
|
|
41
|
+
onSelect(value);
|
|
42
|
+
setIsOpen(false);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const currentOption = options.find(opt => opt.value === currentValue);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div className="rte-dropdown" ref={dropdownRef}>
|
|
49
|
+
<button
|
|
50
|
+
type="button"
|
|
51
|
+
onClick={() => !disabled && setIsOpen(!isOpen)}
|
|
52
|
+
disabled={disabled}
|
|
53
|
+
className={`rte-toolbar-button rte-dropdown-button ${currentOption ? 'rte-dropdown-button-has-value' : ''}`}
|
|
54
|
+
title={label}
|
|
55
|
+
aria-label={label}
|
|
56
|
+
>
|
|
57
|
+
<Icon icon={icon} width={18} height={18} />
|
|
58
|
+
{currentOption && (
|
|
59
|
+
<span className="rte-dropdown-value">{currentOption.label}</span>
|
|
60
|
+
)}
|
|
61
|
+
</button>
|
|
62
|
+
{isOpen && (
|
|
63
|
+
<div className="rte-dropdown-menu">
|
|
64
|
+
{options.map((option) => (
|
|
65
|
+
<button
|
|
66
|
+
key={option.value}
|
|
67
|
+
type="button"
|
|
68
|
+
className={`rte-dropdown-item ${currentValue === option.value ? 'rte-dropdown-item-active' : ''}`}
|
|
69
|
+
onClick={() => handleSelect(option.value)}
|
|
70
|
+
>
|
|
71
|
+
{option.color && (
|
|
72
|
+
<span
|
|
73
|
+
className={`rte-dropdown-color-preview ${currentValue === option.value ? 'active' : ''}`}
|
|
74
|
+
style={{ backgroundColor: option.color }}
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
{option.preview && !option.headingPreview && (
|
|
78
|
+
<span
|
|
79
|
+
className="rte-dropdown-fontsize-preview"
|
|
80
|
+
style={{ fontSize: `${option.preview}px` }}
|
|
81
|
+
>
|
|
82
|
+
Aa
|
|
83
|
+
</span>
|
|
84
|
+
)}
|
|
85
|
+
{option.headingPreview && (
|
|
86
|
+
<span
|
|
87
|
+
className={`rte-dropdown-heading-preview ${option.headingPreview}`}
|
|
88
|
+
>
|
|
89
|
+
{option.headingPreview === 'p' ? 'Normal' : option.headingPreview.toUpperCase()}
|
|
90
|
+
</span>
|
|
91
|
+
)}
|
|
92
|
+
{option.icon && <Icon icon={option.icon} width={16} height={16} />}
|
|
93
|
+
<span style={{ flex: 1, fontWeight: currentValue === option.value ? 600 : 400 }}>
|
|
94
|
+
{option.label}
|
|
95
|
+
</span>
|
|
96
|
+
</button>
|
|
97
|
+
))}
|
|
98
|
+
</div>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|