@tnd028/strapi-plugin-tiptap-editor 0.0.1
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 +3 -0
- package/dist/_chunks/Alignment-B0f2-LO0.js +135 -0
- package/dist/_chunks/Alignment-qMOzO-n2.mjs +133 -0
- package/dist/_chunks/Blockquote-9wBGDz3L.mjs +34 -0
- package/dist/_chunks/Blockquote-DeGUfK27.js +36 -0
- package/dist/_chunks/Bold-C-0g6Ayd.mjs +46 -0
- package/dist/_chunks/Bold-ClnPsPHt.js +48 -0
- package/dist/_chunks/ColorAndHighlight-BMmtoSpj.js +217 -0
- package/dist/_chunks/ColorAndHighlight-t1Ui5tcL.mjs +215 -0
- package/dist/_chunks/Emoji-Bm1_vSh5.mjs +263 -0
- package/dist/_chunks/Emoji-C-LQZ4Z3.js +265 -0
- package/dist/_chunks/Heading-BDJqd1Qw.js +125 -0
- package/dist/_chunks/Heading-BycRob5M.mjs +123 -0
- package/dist/_chunks/HorizontalRule-CJlDmdma.js +34 -0
- package/dist/_chunks/HorizontalRule-CzQCeC3b.mjs +32 -0
- package/dist/_chunks/Iframe-DCBWSb0v.mjs +165 -0
- package/dist/_chunks/Iframe-Dyn_2cMB.js +167 -0
- package/dist/_chunks/ImagePlaceholder-C14kojd5.js +71 -0
- package/dist/_chunks/ImagePlaceholder-DtrSuhf_.mjs +69 -0
- package/dist/_chunks/Italic-BfpKX0KX.mjs +34 -0
- package/dist/_chunks/Italic-DdhVL78v.js +36 -0
- package/dist/_chunks/Link-BuYDqSqo.js +61 -0
- package/dist/_chunks/Link-DUV5Ybep.mjs +59 -0
- package/dist/_chunks/Lists-BKopoFR6.js +107 -0
- package/dist/_chunks/Lists-DsKxj3MD.mjs +105 -0
- package/dist/_chunks/Redo-1mEX1yOd.js +35 -0
- package/dist/_chunks/Redo-Ca3VQxSe.mjs +33 -0
- package/dist/_chunks/SearchAndReplace-DmU5DlWv.mjs +347 -0
- package/dist/_chunks/SearchAndReplace-DzNdbTWJ.js +349 -0
- package/dist/_chunks/Strikethrough-BygxCHak.mjs +121 -0
- package/dist/_chunks/Strikethrough-DQfR4OFk.js +123 -0
- package/dist/_chunks/Table-BhbZ2Blv.mjs +123 -0
- package/dist/_chunks/Table-DLaqBAbz.js +125 -0
- package/dist/_chunks/TiptapEditorInput-BDE09h5-.mjs +6802 -0
- package/dist/_chunks/TiptapEditorInput-vfLsCt1p.js +6854 -0
- package/dist/_chunks/Undo-BuT4OkoE.js +32 -0
- package/dist/_chunks/Undo-PL5n4axf.mjs +30 -0
- package/dist/_chunks/en-B4KWt_jN.js +4 -0
- package/dist/_chunks/en-Byx4XI2L.mjs +4 -0
- package/dist/_chunks/index-ku90UbIF.mjs +1397 -0
- package/dist/_chunks/index-wYDv8vsJ.js +1398 -0
- package/dist/admin/index.js +6 -0
- package/dist/admin/index.mjs +6 -0
- package/dist/admin/src/components/ContentEditorInput.d.ts +10 -0
- package/dist/admin/src/components/GlobalStyling.d.ts +4 -0
- package/dist/admin/src/components/Initializer.d.ts +5 -0
- package/dist/admin/src/components/MediaLibraryModal.d.ts +27 -0
- package/dist/admin/src/components/PluginIcon.d.ts +2 -0
- package/dist/admin/src/components/TextEditorInput.d.ts +10 -0
- package/dist/admin/src/components/TiptapEditorInput.d.ts +6 -0
- package/dist/admin/src/components/editor/BaseEditor.d.ts +22 -0
- package/dist/admin/src/components/editor/ContentEditor.d.ts +10 -0
- package/dist/admin/src/components/editor/TextEditor.d.ts +10 -0
- package/dist/admin/src/components/editor/extensions/Heading.d.ts +2 -0
- package/dist/admin/src/components/editor/extensions/Iframe.d.ts +24 -0
- package/dist/admin/src/components/editor/extensions/Image.d.ts +3 -0
- package/dist/admin/src/components/editor/extensions/ImagePlaceholder.d.ts +15 -0
- package/dist/admin/src/components/editor/extensions/custom-component/CustomComponentEditPopover.d.ts +1 -0
- package/dist/admin/src/components/editor/extensions/custom-component/CustomComponentExtension.d.ts +3 -0
- package/dist/admin/src/components/editor/extensions/custom-component/CustomComponentInsertPopover.d.ts +13 -0
- package/dist/admin/src/components/editor/extensions/custom-component/CustomComponentRenderer.d.ts +1 -0
- package/dist/admin/src/components/editor/extensions/custom-component/Store.d.ts +20 -0
- package/dist/admin/src/components/editor/extensions/custom-component/types.d.ts +33 -0
- package/dist/admin/src/components/editor/extensions/fileHandler.d.ts +12 -0
- package/dist/admin/src/components/editor/extensions/link.d.ts +1 -0
- package/dist/admin/src/components/editor/extensions/noNewLine.d.ts +2 -0
- package/dist/admin/src/components/editor/extensions/resetMarksOnEnter.d.ts +2 -0
- package/dist/admin/src/components/editor/extensions/searchAndReplace.d.ts +53 -0
- package/dist/admin/src/components/editor/partials/EditorProvider.d.ts +13 -0
- package/dist/admin/src/components/editor/partials/LinkBubbleMenu.d.ts +5 -0
- package/dist/admin/src/components/editor/partials/LinkEditBlock.d.ts +9 -0
- package/dist/admin/src/components/editor/partials/LinkPopoverBlock.d.ts +8 -0
- package/dist/admin/src/components/editor/partials/ToolbarButton.d.ts +11 -0
- package/dist/admin/src/components/editor/partials/ToolbarButtons.d.ts +25 -0
- package/dist/admin/src/components/editor/toolbars/Alignment.d.ts +1 -0
- package/dist/admin/src/components/editor/toolbars/Blockquote.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/Bold.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/BulletList.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/ColorAndHighlight.d.ts +5 -0
- package/dist/admin/src/components/editor/toolbars/Emoji.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/Heading.d.ts +1 -0
- package/dist/admin/src/components/editor/toolbars/HorizontalRule.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/Iframe.d.ts +3 -0
- package/dist/admin/src/components/editor/toolbars/ImagePlaceholder.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/Italic.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/Link.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/Lists.d.ts +1 -0
- package/dist/admin/src/components/editor/toolbars/OrderedList.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/Redo.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/SearchAndReplace.d.ts +1 -0
- package/dist/admin/src/components/editor/toolbars/Strikethrough.d.ts +4 -0
- package/dist/admin/src/components/editor/toolbars/Table.d.ts +1 -0
- package/dist/admin/src/components/editor/toolbars/Undo.d.ts +4 -0
- package/dist/admin/src/components/editor/useEditor.d.ts +18 -0
- package/dist/admin/src/components/editor/utils.d.ts +28 -0
- package/dist/admin/src/components/ui/button.d.ts +9 -0
- package/dist/admin/src/components/ui/dropdown-menu.d.ts +27 -0
- package/dist/admin/src/components/ui/input.d.ts +6 -0
- package/dist/admin/src/components/ui/label.d.ts +7 -0
- package/dist/admin/src/components/ui/separator.d.ts +7 -0
- package/dist/admin/src/components/ui/toggle.d.ts +17 -0
- package/dist/admin/src/components/ui/tooltip.d.ts +7 -0
- package/dist/admin/src/config/index.d.ts +2 -0
- package/dist/admin/src/config/pluginConfig.d.ts +20 -0
- package/dist/admin/src/config/types.d.ts +109 -0
- package/dist/admin/src/errorSlicer.d.ts +4 -0
- package/dist/admin/src/exports.d.ts +4 -0
- package/dist/admin/src/hooks/useDebounceCallback.d.ts +9 -0
- package/dist/admin/src/index.d.ts +25 -0
- package/dist/admin/src/pluginId.d.ts +5 -0
- package/dist/admin/src/theme/additional.d.ts +1 -0
- package/dist/admin/src/theme/colorScheme.d.ts +2 -0
- package/dist/admin/src/theme/colors.d.ts +1 -0
- package/dist/admin/src/theme/common.d.ts +1 -0
- package/dist/admin/src/theme/index.d.ts +2 -0
- package/dist/admin/src/types.d.ts +15 -0
- package/dist/admin/src/utils/dom.d.ts +7 -0
- package/dist/admin/src/utils/getTranslation.d.ts +7 -0
- package/dist/admin/src/utils/isImageResponsive.d.ts +8 -0
- package/dist/admin/src/utils/localStorage.d.ts +21 -0
- package/dist/admin/src/utils/prefixWithBackendUrl.d.ts +6 -0
- package/dist/admin/src/utils/utils.d.ts +7 -0
- package/dist/server/index.js +15 -0
- package/dist/server/index.mjs +16 -0
- package/dist/server/src/index.d.ts +7 -0
- package/package.json +116 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Popover } from "@strapi/design-system";
|
|
3
|
+
import { HighlighterIcon, BaselineIcon, ChevronDown, Check } from "lucide-react";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import styled from "styled-components";
|
|
6
|
+
import { u as useEditorContext, T as ToolbarButton, S as Separator } from "./TiptapEditorInput-BDE09h5-.mjs";
|
|
7
|
+
const TEXT_COLORS = [
|
|
8
|
+
{ name: "Default", color: "inherit" },
|
|
9
|
+
{ name: "Gray", color: "#6B7280" },
|
|
10
|
+
{ name: "Brown", color: "#92400E" },
|
|
11
|
+
{ name: "Orange", color: "#EA580C" },
|
|
12
|
+
{ name: "Yellow", color: "#CA8A04" },
|
|
13
|
+
{ name: "Green", color: "#16A34A" },
|
|
14
|
+
{ name: "Blue", color: "#2563EB" },
|
|
15
|
+
{ name: "Purple", color: "#9333EA" },
|
|
16
|
+
{ name: "Pink", color: "#DB2777" },
|
|
17
|
+
{ name: "Red", color: "#DC2626" }
|
|
18
|
+
];
|
|
19
|
+
const HIGHLIGHT_COLORS = [
|
|
20
|
+
{ name: "Default", color: "transparent" },
|
|
21
|
+
{ name: "Gray", color: "#F3F4F6" },
|
|
22
|
+
{ name: "Brown", color: "#FEF3C7" },
|
|
23
|
+
{ name: "Orange", color: "#FFEDD5" },
|
|
24
|
+
{ name: "Yellow", color: "#FEF9C3" },
|
|
25
|
+
{ name: "Green", color: "#DCFCE7" },
|
|
26
|
+
{ name: "Blue", color: "#DBEAFE" },
|
|
27
|
+
{ name: "Purple", color: "#F3E8FF" },
|
|
28
|
+
{ name: "Pink", color: "#FCE7F3" },
|
|
29
|
+
{ name: "Red", color: "#FEE2E2" }
|
|
30
|
+
];
|
|
31
|
+
const ColorGrid = styled.div`
|
|
32
|
+
display: grid;
|
|
33
|
+
grid-template-columns: repeat(5, 1fr);
|
|
34
|
+
gap: 4px;
|
|
35
|
+
`;
|
|
36
|
+
const CompactColorButton = styled.button`
|
|
37
|
+
width: 24px;
|
|
38
|
+
height: 24px;
|
|
39
|
+
border-radius: 4px;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
border: 1px solid ${(props) => props.theme.colors.neutral200};
|
|
45
|
+
|
|
46
|
+
${(props) => props.$isHighlight ? `background-color: ${props.$color}; color: ${props.theme.colors.neutral800};` : `background-color: transparent; color: ${props.$color === "inherit" ? props.theme.colors.neutral800 : props.$color};`}
|
|
47
|
+
|
|
48
|
+
${(props) => props.$color === "inherit" && !props.$isHighlight && `
|
|
49
|
+
background: linear-gradient(to bottom right, transparent 48%, #ff0000 48%, #ff0000 52%, transparent 52%);
|
|
50
|
+
border-color: ${props.theme.colors.neutral300};
|
|
51
|
+
color: ${props.theme.colors.neutral800};
|
|
52
|
+
`}
|
|
53
|
+
|
|
54
|
+
${(props) => props.$color === "transparent" && props.$isHighlight && `
|
|
55
|
+
background: linear-gradient(to bottom right, transparent 48%, #ff0000 48%, #ff0000 52%, transparent 52%);
|
|
56
|
+
background-color: ${props.theme.colors.neutral100};
|
|
57
|
+
`}
|
|
58
|
+
|
|
59
|
+
&:hover {
|
|
60
|
+
border-color: ${(props) => props.theme.colors.primary500};
|
|
61
|
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
${(props) => props.$isActive && `
|
|
65
|
+
border-color: ${props.theme.colors.primary600};
|
|
66
|
+
box-shadow: 0 0 0 1px ${props.theme.colors.primary600};
|
|
67
|
+
transform: scale(1.05);
|
|
68
|
+
`}
|
|
69
|
+
`;
|
|
70
|
+
const CheckIcon = styled(Check)`
|
|
71
|
+
width: 12px;
|
|
72
|
+
height: 12px;
|
|
73
|
+
color: ${(props) => props.theme.colors.neutral800};
|
|
74
|
+
filter: drop-shadow(0 0 1px white);
|
|
75
|
+
`;
|
|
76
|
+
const SectionTitle = styled.div`
|
|
77
|
+
margin: 6px 0;
|
|
78
|
+
padding: 0 4px;
|
|
79
|
+
font-size: 11px;
|
|
80
|
+
text-transform: uppercase;
|
|
81
|
+
letter-spacing: 0.5px;
|
|
82
|
+
font-weight: 600;
|
|
83
|
+
color: ${(props) => props.theme.colors.neutral600};
|
|
84
|
+
`;
|
|
85
|
+
const ChevronIcon = styled(ChevronDown)`
|
|
86
|
+
width: 12px;
|
|
87
|
+
height: 12px;
|
|
88
|
+
`;
|
|
89
|
+
const ToolbarContentWrapper = styled.div`
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
gap: 2px;
|
|
93
|
+
padding: 0 2px 0 2px;
|
|
94
|
+
`;
|
|
95
|
+
const ToolbarContent = ({ children, dropdown }) => /* @__PURE__ */ jsxs(ToolbarContentWrapper, { children: [
|
|
96
|
+
children,
|
|
97
|
+
dropdown && /* @__PURE__ */ jsx(ChevronIcon, {})
|
|
98
|
+
] });
|
|
99
|
+
const PopoverContent = styled(Popover.Content)`
|
|
100
|
+
background-color: ${(props) => props.theme.colors.neutral0};
|
|
101
|
+
border: 1px solid ${(props) => props.theme.colors.neutral300};
|
|
102
|
+
border-radius: 4px;
|
|
103
|
+
padding: 8px;
|
|
104
|
+
width: 180px;
|
|
105
|
+
box-shadow: ${(props) => props.theme.shadows.popupShadow};
|
|
106
|
+
`;
|
|
107
|
+
const SeparatorStyled = styled(Separator)`
|
|
108
|
+
margin: 8px 0;
|
|
109
|
+
`;
|
|
110
|
+
const ColorButtonComponent = ({
|
|
111
|
+
name,
|
|
112
|
+
color,
|
|
113
|
+
isActive,
|
|
114
|
+
onClick,
|
|
115
|
+
isHighlight
|
|
116
|
+
}) => /* @__PURE__ */ jsxs(
|
|
117
|
+
CompactColorButton,
|
|
118
|
+
{
|
|
119
|
+
$isActive: isActive,
|
|
120
|
+
$color: color,
|
|
121
|
+
$isHighlight: isHighlight,
|
|
122
|
+
onClick,
|
|
123
|
+
type: "button",
|
|
124
|
+
"aria-label": name,
|
|
125
|
+
children: [
|
|
126
|
+
!isHighlight && color !== "inherit" && /* @__PURE__ */ jsx(BaselineIcon, {}),
|
|
127
|
+
isHighlight && isActive && /* @__PURE__ */ jsx(CheckIcon, {})
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
const ColorAndHighlightToolbar = () => {
|
|
132
|
+
const { editor } = useEditorContext();
|
|
133
|
+
const [recentColors, setRecentColors] = useState([]);
|
|
134
|
+
const currentColor = editor?.getAttributes("textStyle").color;
|
|
135
|
+
const currentHighlight = editor?.getAttributes("highlight").color;
|
|
136
|
+
const addToRecent = (color, isHighlight) => {
|
|
137
|
+
const isDefault = isHighlight ? color === "transparent" : color === "inherit" || color === "";
|
|
138
|
+
if (isDefault) return;
|
|
139
|
+
setRecentColors((prev) => {
|
|
140
|
+
const existing = prev.filter((c) => !(c.color === color && c.isHighlight === isHighlight));
|
|
141
|
+
return [{ color, isHighlight }, ...existing].slice(0, 5);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
const handleSetColor = (color) => {
|
|
145
|
+
editor?.chain().focus().setColor(color === currentColor ? "" : color).run();
|
|
146
|
+
if (color !== currentColor) {
|
|
147
|
+
addToRecent(color, false);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const handleSetHighlight = (color) => {
|
|
151
|
+
editor?.chain().focus().setHighlight(color === currentHighlight ? { color: "" } : { color }).run();
|
|
152
|
+
if (color !== currentHighlight) {
|
|
153
|
+
addToRecent(color, true);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const isDisabled = !editor?.can().chain().setHighlight().run() || !editor?.can().chain().setColor("").run();
|
|
157
|
+
return /* @__PURE__ */ jsx(Popover.Root, { children: /* @__PURE__ */ jsxs("div", { style: { position: "relative", height: "100%" }, children: [
|
|
158
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { disabled: isDisabled, children: /* @__PURE__ */ jsx(
|
|
159
|
+
ToolbarButton,
|
|
160
|
+
{
|
|
161
|
+
tooltip: "Text Color & Highlight",
|
|
162
|
+
"aria-label": "Set color & highlight",
|
|
163
|
+
style: {
|
|
164
|
+
color: currentColor,
|
|
165
|
+
backgroundColor: currentHighlight
|
|
166
|
+
},
|
|
167
|
+
children: /* @__PURE__ */ jsx(ToolbarContent, { children: /* @__PURE__ */ jsx(HighlighterIcon, {}) })
|
|
168
|
+
}
|
|
169
|
+
) }),
|
|
170
|
+
/* @__PURE__ */ jsxs(PopoverContent, { align: "start", children: [
|
|
171
|
+
recentColors.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
172
|
+
/* @__PURE__ */ jsx(SectionTitle, { children: "Recently Used" }),
|
|
173
|
+
/* @__PURE__ */ jsx(ColorGrid, { children: recentColors.map((recent, index) => /* @__PURE__ */ jsx(
|
|
174
|
+
ColorButtonComponent,
|
|
175
|
+
{
|
|
176
|
+
name: recent.color,
|
|
177
|
+
color: recent.color,
|
|
178
|
+
isActive: recent.isHighlight ? currentHighlight === recent.color : currentColor === recent.color,
|
|
179
|
+
onClick: () => recent.isHighlight ? handleSetHighlight(recent.color) : handleSetColor(recent.color),
|
|
180
|
+
isHighlight: recent.isHighlight
|
|
181
|
+
},
|
|
182
|
+
`${recent.color}-${recent.isHighlight}-${index}`
|
|
183
|
+
)) }),
|
|
184
|
+
/* @__PURE__ */ jsx(SeparatorStyled, {})
|
|
185
|
+
] }),
|
|
186
|
+
/* @__PURE__ */ jsx(SectionTitle, { children: "Text Color" }),
|
|
187
|
+
/* @__PURE__ */ jsx(ColorGrid, { children: TEXT_COLORS.map(({ name, color }) => /* @__PURE__ */ jsx(
|
|
188
|
+
ColorButtonComponent,
|
|
189
|
+
{
|
|
190
|
+
name,
|
|
191
|
+
color,
|
|
192
|
+
isActive: currentColor === color,
|
|
193
|
+
onClick: () => handleSetColor(color)
|
|
194
|
+
},
|
|
195
|
+
name
|
|
196
|
+
)) }),
|
|
197
|
+
/* @__PURE__ */ jsx(SeparatorStyled, {}),
|
|
198
|
+
/* @__PURE__ */ jsx(SectionTitle, { children: "Background" }),
|
|
199
|
+
/* @__PURE__ */ jsx(ColorGrid, { children: HIGHLIGHT_COLORS.map(({ name, color }) => /* @__PURE__ */ jsx(
|
|
200
|
+
ColorButtonComponent,
|
|
201
|
+
{
|
|
202
|
+
name,
|
|
203
|
+
color,
|
|
204
|
+
isActive: currentHighlight === color,
|
|
205
|
+
onClick: () => handleSetHighlight(color),
|
|
206
|
+
isHighlight: true
|
|
207
|
+
},
|
|
208
|
+
name
|
|
209
|
+
)) })
|
|
210
|
+
] })
|
|
211
|
+
] }) });
|
|
212
|
+
};
|
|
213
|
+
export {
|
|
214
|
+
ColorAndHighlightToolbar
|
|
215
|
+
};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useRef, useEffect, useMemo } from "react";
|
|
3
|
+
import { Clock, Smile, Cat, Coffee, Activity, Car, Lightbulb, Hash, Flag, Search } from "lucide-react";
|
|
4
|
+
import { u as useEditorContext, T as ToolbarButton } from "./TiptapEditorInput-BDE09h5-.mjs";
|
|
5
|
+
import { Popover } from "@strapi/design-system";
|
|
6
|
+
import styled from "styled-components";
|
|
7
|
+
import { gitHubEmojis } from "@tiptap/extension-emoji";
|
|
8
|
+
const EmojiIcon = styled(Smile)`
|
|
9
|
+
width: 16px;
|
|
10
|
+
height: 16px;
|
|
11
|
+
`;
|
|
12
|
+
const PopoverContent = styled(Popover.Content)`
|
|
13
|
+
padding: 0;
|
|
14
|
+
background: ${({ theme }) => theme.colors.neutral0};
|
|
15
|
+
border: 1px solid ${({ theme }) => theme.colors.neutral200};
|
|
16
|
+
box-shadow: ${({ theme }) => theme.shadows.filterShadow};
|
|
17
|
+
border-radius: 4px;
|
|
18
|
+
width: 320px;
|
|
19
|
+
max-width: 90vw;
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
`;
|
|
24
|
+
const SearchContainer = styled.div`
|
|
25
|
+
padding: 8px;
|
|
26
|
+
border-bottom: 1px solid ${({ theme }) => theme.colors.neutral200};
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: 8px;
|
|
30
|
+
background-color: ${({ theme }) => theme.colors.neutral0};
|
|
31
|
+
`;
|
|
32
|
+
const SearchIcon = styled(Search)`
|
|
33
|
+
width: 14px;
|
|
34
|
+
height: 14px;
|
|
35
|
+
color: ${({ theme }) => theme.colors.neutral500};
|
|
36
|
+
`;
|
|
37
|
+
const SearchInput = styled.input`
|
|
38
|
+
border: none;
|
|
39
|
+
background: none;
|
|
40
|
+
outline: none;
|
|
41
|
+
width: 100%;
|
|
42
|
+
font-size: 13px;
|
|
43
|
+
color: ${({ theme }) => theme.colors.neutral800};
|
|
44
|
+
|
|
45
|
+
&::placeholder {
|
|
46
|
+
color: ${({ theme }) => theme.colors.neutral500};
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
const ScrollContainer = styled.div`
|
|
50
|
+
max-height: 280px;
|
|
51
|
+
height: 280px;
|
|
52
|
+
overflow-y: auto;
|
|
53
|
+
padding: 12px;
|
|
54
|
+
scroll-behavior: smooth;
|
|
55
|
+
`;
|
|
56
|
+
const EmojiGrid = styled.div`
|
|
57
|
+
display: grid;
|
|
58
|
+
grid-template-columns: repeat(8, 1fr);
|
|
59
|
+
gap: 4px;
|
|
60
|
+
margin-bottom: 12px;
|
|
61
|
+
`;
|
|
62
|
+
const EmojiItem = styled.button`
|
|
63
|
+
border: none;
|
|
64
|
+
background: none;
|
|
65
|
+
font-size: 20px;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
padding: 4px;
|
|
68
|
+
width: 32px;
|
|
69
|
+
height: 32px;
|
|
70
|
+
border-radius: 4px;
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
justify-content: center;
|
|
74
|
+
|
|
75
|
+
&:hover {
|
|
76
|
+
background-color: ${({ theme }) => theme.colors.neutral100};
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
const TabBar = styled.div`
|
|
80
|
+
display: flex;
|
|
81
|
+
align-items: center;
|
|
82
|
+
justify-content: space-between;
|
|
83
|
+
padding: 8px 12px;
|
|
84
|
+
border-bottom: 1px solid ${({ theme }) => theme.colors.neutral200};
|
|
85
|
+
background-color: ${({ theme }) => theme.colors.neutral100};
|
|
86
|
+
`;
|
|
87
|
+
const TabButton = styled.button`
|
|
88
|
+
border: none;
|
|
89
|
+
background: none;
|
|
90
|
+
padding: 4px;
|
|
91
|
+
border-radius: 4px;
|
|
92
|
+
cursor: pointer;
|
|
93
|
+
color: ${({ theme, $isActive }) => $isActive ? theme.colors.primary600 : theme.colors.neutral500};
|
|
94
|
+
background-color: ${({ theme, $isActive }) => $isActive ? theme.colors.primary100 : "transparent"};
|
|
95
|
+
|
|
96
|
+
&:hover {
|
|
97
|
+
background-color: ${({ theme }) => theme.colors.neutral200};
|
|
98
|
+
color: ${({ theme }) => theme.colors.neutral700};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
svg {
|
|
102
|
+
width: 18px;
|
|
103
|
+
height: 18px;
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
const SectionTitle = styled.div`
|
|
107
|
+
font-size: 11px;
|
|
108
|
+
font-weight: 600;
|
|
109
|
+
text-transform: uppercase;
|
|
110
|
+
color: ${({ theme }) => theme.colors.neutral500};
|
|
111
|
+
margin-bottom: 4px;
|
|
112
|
+
margin-top: 4px;
|
|
113
|
+
`;
|
|
114
|
+
const CATEGORIES = [
|
|
115
|
+
{ id: "recent", icon: Clock, title: "Recent", tags: [] },
|
|
116
|
+
{ id: "smileys", icon: Smile, title: "Smileys & People", tags: ["face", "smile", "person", "joy", "happy", "sad", "mad", "hand", "body"] },
|
|
117
|
+
{ id: "nature", icon: Cat, title: "Animals & Nature", tags: ["animal", "nature", "cat", "dog", "plant", "flower", "weather"] },
|
|
118
|
+
{ id: "food", icon: Coffee, title: "Food & Drink", tags: ["food", "drink", "fruit", "vegetable", "meal"] },
|
|
119
|
+
{ id: "activity", icon: Activity, title: "Activity", tags: ["activity", "sport", "game", "play"] },
|
|
120
|
+
{ id: "travel", icon: Car, title: "Travel & Places", tags: ["travel", "place", "car", "vehicle", "building", "map"] },
|
|
121
|
+
{ id: "objects", icon: Lightbulb, title: "Objects", tags: ["object", "tool", "computer", "device", "light"] },
|
|
122
|
+
{ id: "symbols", icon: Hash, title: "Symbols", tags: ["symbol", "shape", "sign", "arrow"] },
|
|
123
|
+
{ id: "flags", icon: Flag, title: "Flags", tags: ["flag"] }
|
|
124
|
+
];
|
|
125
|
+
const EmojiToolbar = forwardRef(
|
|
126
|
+
({ className, onClick, children, ...props }, ref) => {
|
|
127
|
+
const { editor } = useEditorContext();
|
|
128
|
+
const [open, setOpen] = useState(false);
|
|
129
|
+
const [activeCategory, setActiveCategory] = useState("recent");
|
|
130
|
+
const [recent, setRecent] = useState([]);
|
|
131
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
132
|
+
const searchInputRef = useRef(null);
|
|
133
|
+
const scrollRef = useRef(null);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const stored = localStorage.getItem("tiptap-recent-emojis");
|
|
136
|
+
if (stored) {
|
|
137
|
+
try {
|
|
138
|
+
const parsed = JSON.parse(stored);
|
|
139
|
+
setRecent(parsed);
|
|
140
|
+
if (parsed.length === 0) {
|
|
141
|
+
setActiveCategory("smileys");
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
console.error("Failed to parse recent emojis", e);
|
|
145
|
+
setActiveCategory("smileys");
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
setActiveCategory("smileys");
|
|
149
|
+
}
|
|
150
|
+
}, []);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (open) {
|
|
153
|
+
setTimeout(() => {
|
|
154
|
+
searchInputRef.current?.focus();
|
|
155
|
+
}, 100);
|
|
156
|
+
} else {
|
|
157
|
+
setSearchQuery("");
|
|
158
|
+
}
|
|
159
|
+
}, [open]);
|
|
160
|
+
const handleEmojiSelect = (emoji) => {
|
|
161
|
+
editor.chain().focus().setEmoji(emoji.name).run();
|
|
162
|
+
const newRecent = [emoji.name, ...recent.filter((n) => n !== emoji.name)].slice(0, 24);
|
|
163
|
+
setRecent(newRecent);
|
|
164
|
+
localStorage.setItem("tiptap-recent-emojis", JSON.stringify(newRecent));
|
|
165
|
+
setOpen(false);
|
|
166
|
+
};
|
|
167
|
+
const scrollToCategory = (catId) => {
|
|
168
|
+
setActiveCategory(catId);
|
|
169
|
+
const element = document.getElementById(`emoji-category-${catId}`);
|
|
170
|
+
if (element && scrollRef.current) {
|
|
171
|
+
scrollRef.current.scrollTop = element.offsetTop - scrollRef.current.offsetTop - 10;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const categorizedEmojis = useMemo(() => {
|
|
175
|
+
const groups = {};
|
|
176
|
+
groups["recent"] = recent.map((name) => gitHubEmojis.find((e) => e.name === name)).filter(Boolean);
|
|
177
|
+
CATEGORIES.slice(1).forEach((cat) => {
|
|
178
|
+
groups[cat.id] = gitHubEmojis.filter(
|
|
179
|
+
(emoji) => emoji.tags.some((tag) => cat.tags.some((catTag) => tag.includes(catTag)))
|
|
180
|
+
).slice(0, 100);
|
|
181
|
+
});
|
|
182
|
+
return groups;
|
|
183
|
+
}, [recent]);
|
|
184
|
+
const searchResults = useMemo(() => {
|
|
185
|
+
if (!searchQuery.trim()) return [];
|
|
186
|
+
const query = searchQuery.toLowerCase();
|
|
187
|
+
return gitHubEmojis.filter(
|
|
188
|
+
(e) => e.name.toLowerCase().includes(query) || e.shortcodes.some((s) => s.includes(query)) || e.tags.some((t) => t.includes(query))
|
|
189
|
+
).slice(0, 100);
|
|
190
|
+
}, [searchQuery]);
|
|
191
|
+
return /* @__PURE__ */ jsxs(Popover.Root, { open, onOpenChange: setOpen, children: [
|
|
192
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { children: /* @__PURE__ */ jsx(
|
|
193
|
+
ToolbarButton,
|
|
194
|
+
{
|
|
195
|
+
tooltip: "Insert Emoji",
|
|
196
|
+
"aria-label": "Insert emoji",
|
|
197
|
+
ref,
|
|
198
|
+
isActive: open,
|
|
199
|
+
...props,
|
|
200
|
+
children: children || /* @__PURE__ */ jsx(EmojiIcon, {})
|
|
201
|
+
}
|
|
202
|
+
) }),
|
|
203
|
+
/* @__PURE__ */ jsxs(PopoverContent, { align: "start", sideOffset: 4, children: [
|
|
204
|
+
/* @__PURE__ */ jsx(TabBar, { children: CATEGORIES.map((cat) => {
|
|
205
|
+
const Icon = cat.icon;
|
|
206
|
+
return /* @__PURE__ */ jsx(
|
|
207
|
+
TabButton,
|
|
208
|
+
{
|
|
209
|
+
$isActive: activeCategory === cat.id && !searchQuery,
|
|
210
|
+
onClick: () => scrollToCategory(cat.id),
|
|
211
|
+
title: cat.title,
|
|
212
|
+
type: "button",
|
|
213
|
+
children: /* @__PURE__ */ jsx(Icon, {})
|
|
214
|
+
},
|
|
215
|
+
cat.id
|
|
216
|
+
);
|
|
217
|
+
}) }),
|
|
218
|
+
/* @__PURE__ */ jsxs(SearchContainer, { children: [
|
|
219
|
+
/* @__PURE__ */ jsx(SearchIcon, {}),
|
|
220
|
+
/* @__PURE__ */ jsx(
|
|
221
|
+
SearchInput,
|
|
222
|
+
{
|
|
223
|
+
ref: searchInputRef,
|
|
224
|
+
placeholder: "Search emojis...",
|
|
225
|
+
value: searchQuery,
|
|
226
|
+
onChange: (e) => setSearchQuery(e.target.value)
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
] }),
|
|
230
|
+
/* @__PURE__ */ jsx(ScrollContainer, { ref: scrollRef, children: searchQuery ? /* @__PURE__ */ jsx(Fragment, { children: searchResults.length > 0 ? /* @__PURE__ */ jsx(EmojiGrid, { children: searchResults.map((item) => /* @__PURE__ */ jsx(
|
|
231
|
+
EmojiItem,
|
|
232
|
+
{
|
|
233
|
+
onClick: () => handleEmojiSelect(item),
|
|
234
|
+
title: item.name,
|
|
235
|
+
type: "button",
|
|
236
|
+
children: item.emoji
|
|
237
|
+
},
|
|
238
|
+
item.name
|
|
239
|
+
)) }) : /* @__PURE__ */ jsx("div", { style: { textAlign: "center", color: "#666", fontSize: "13px", paddingTop: "20px" }, children: "No results found" }) }) : /* @__PURE__ */ jsx(Fragment, { children: CATEGORIES.map((cat) => {
|
|
240
|
+
const emojis = categorizedEmojis[cat.id];
|
|
241
|
+
if (!emojis || emojis.length === 0) return null;
|
|
242
|
+
return /* @__PURE__ */ jsxs("div", { id: `emoji-category-${cat.id}`, children: [
|
|
243
|
+
/* @__PURE__ */ jsx(SectionTitle, { children: cat.title }),
|
|
244
|
+
/* @__PURE__ */ jsx(EmojiGrid, { children: emojis.map((item) => /* @__PURE__ */ jsx(
|
|
245
|
+
EmojiItem,
|
|
246
|
+
{
|
|
247
|
+
onClick: () => handleEmojiSelect(item),
|
|
248
|
+
title: item.name,
|
|
249
|
+
type: "button",
|
|
250
|
+
children: item.emoji
|
|
251
|
+
},
|
|
252
|
+
item.name
|
|
253
|
+
)) })
|
|
254
|
+
] }, cat.id);
|
|
255
|
+
}) }) })
|
|
256
|
+
] })
|
|
257
|
+
] });
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
EmojiToolbar.displayName = "EmojiToolbar";
|
|
261
|
+
export {
|
|
262
|
+
EmojiToolbar
|
|
263
|
+
};
|