ritext 1.0.0 → 1.0.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/README.md +21 -0
- package/dist/index.css +390 -0
- package/dist/index.d.mts +37 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +315 -0
- package/dist/index.mjs +278 -0
- package/package.json +77 -7
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<br/>
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://res.cloudinary.com/dub0dpenl/image/upload/v1731780157/Personal%20Logo/logo-white_e6fujz.png">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://res.cloudinary.com/dub0dpenl/image/upload/v1731780152/Personal%20Logo/logo-dark_qqwrqu.png">
|
|
5
|
+
<img alt="Siam Ahnaf" src="https://res.cloudinary.com/dub0dpenl/image/upload/v1731780152/Personal%20Logo/logo-dark_qqwrqu.png" height="auto" width="240">
|
|
6
|
+
</picture>
|
|
7
|
+
<br/> <br/>
|
|
8
|
+
|
|
9
|
+
# Ritext
|
|
10
|
+
Ritext is a modern WYSIWYG rich text editor built with Tailwind CSS, powered by Tiptap. It offers a customizable UI and functional layer that lets you design your own editor controls and toolbars with clean, composable React components—no heavy UI, no extra dependencies beyond Tiptap.
|
|
11
|
+
|
|
12
|
+
<a href="https://www.buymeacoffee.com/siamahnaf" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
|
13
|
+
|
|
14
|
+
# This is an testing phase will publish soon.
|
|
15
|
+
|
|
16
|
+
# Stay in touch
|
|
17
|
+
|
|
18
|
+
- Author - [Siam Ahnaf](https://www.siamahnaf.com/)
|
|
19
|
+
- Website - [https://www.siamahnaf.com/](https://www.siamahnaf.com/)
|
|
20
|
+
- LinkedIn - [https://www.linkedin.com/in/siamahnaf/](https://www.linkedin.com/in/siamahnaf/)
|
|
21
|
+
- Github - [https://github.com/siamahnaf](https://github.com/siamahnaf)
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/* src/global.css */
|
|
2
|
+
@layer properties;
|
|
3
|
+
@layer theme, base, components, utilities;
|
|
4
|
+
@layer theme {
|
|
5
|
+
:root,
|
|
6
|
+
:host {
|
|
7
|
+
--font-sans:
|
|
8
|
+
ui-sans-serif,
|
|
9
|
+
system-ui,
|
|
10
|
+
sans-serif,
|
|
11
|
+
"Apple Color Emoji",
|
|
12
|
+
"Segoe UI Emoji",
|
|
13
|
+
"Segoe UI Symbol",
|
|
14
|
+
"Noto Color Emoji";
|
|
15
|
+
--font-mono:
|
|
16
|
+
ui-monospace,
|
|
17
|
+
SFMono-Regular,
|
|
18
|
+
Menlo,
|
|
19
|
+
Monaco,
|
|
20
|
+
Consolas,
|
|
21
|
+
"Liberation Mono",
|
|
22
|
+
"Courier New",
|
|
23
|
+
monospace;
|
|
24
|
+
--color-gray-50: oklch(98.5% 0.002 247.839);
|
|
25
|
+
--color-gray-100: oklch(96.7% 0.003 264.542);
|
|
26
|
+
--color-gray-200: oklch(92.8% 0.006 264.531);
|
|
27
|
+
--color-white: #fff;
|
|
28
|
+
--spacing: 0.25rem;
|
|
29
|
+
--text-sm: 0.875rem;
|
|
30
|
+
--text-sm--line-height: calc(1.25 / 0.875);
|
|
31
|
+
--radius-md: 0.375rem;
|
|
32
|
+
--radius-lg: 0.5rem;
|
|
33
|
+
--default-transition-duration: 150ms;
|
|
34
|
+
--default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
35
|
+
--default-font-family: var(--font-sans);
|
|
36
|
+
--default-mono-font-family: var(--font-mono);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
@layer base {
|
|
40
|
+
*,
|
|
41
|
+
::after,
|
|
42
|
+
::before,
|
|
43
|
+
::backdrop,
|
|
44
|
+
::file-selector-button {
|
|
45
|
+
box-sizing: border-box;
|
|
46
|
+
margin: 0;
|
|
47
|
+
padding: 0;
|
|
48
|
+
border: 0 solid;
|
|
49
|
+
}
|
|
50
|
+
html,
|
|
51
|
+
:host {
|
|
52
|
+
line-height: 1.5;
|
|
53
|
+
-webkit-text-size-adjust: 100%;
|
|
54
|
+
tab-size: 4;
|
|
55
|
+
font-family: var(--default-font-family, ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
|
|
56
|
+
font-feature-settings: var(--default-font-feature-settings, normal);
|
|
57
|
+
font-variation-settings: var(--default-font-variation-settings, normal);
|
|
58
|
+
-webkit-tap-highlight-color: transparent;
|
|
59
|
+
}
|
|
60
|
+
hr {
|
|
61
|
+
height: 0;
|
|
62
|
+
color: inherit;
|
|
63
|
+
border-top-width: 1px;
|
|
64
|
+
}
|
|
65
|
+
abbr:where([title]) {
|
|
66
|
+
-webkit-text-decoration: underline dotted;
|
|
67
|
+
text-decoration: underline dotted;
|
|
68
|
+
}
|
|
69
|
+
h1,
|
|
70
|
+
h2,
|
|
71
|
+
h3,
|
|
72
|
+
h4,
|
|
73
|
+
h5,
|
|
74
|
+
h6 {
|
|
75
|
+
font-size: inherit;
|
|
76
|
+
font-weight: inherit;
|
|
77
|
+
}
|
|
78
|
+
a {
|
|
79
|
+
color: inherit;
|
|
80
|
+
-webkit-text-decoration: inherit;
|
|
81
|
+
text-decoration: inherit;
|
|
82
|
+
}
|
|
83
|
+
b,
|
|
84
|
+
strong {
|
|
85
|
+
font-weight: bolder;
|
|
86
|
+
}
|
|
87
|
+
code,
|
|
88
|
+
kbd,
|
|
89
|
+
samp,
|
|
90
|
+
pre {
|
|
91
|
+
font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);
|
|
92
|
+
font-feature-settings: var(--default-mono-font-feature-settings, normal);
|
|
93
|
+
font-variation-settings: var(--default-mono-font-variation-settings, normal);
|
|
94
|
+
font-size: 1em;
|
|
95
|
+
}
|
|
96
|
+
small {
|
|
97
|
+
font-size: 80%;
|
|
98
|
+
}
|
|
99
|
+
sub,
|
|
100
|
+
sup {
|
|
101
|
+
font-size: 75%;
|
|
102
|
+
line-height: 0;
|
|
103
|
+
position: relative;
|
|
104
|
+
vertical-align: baseline;
|
|
105
|
+
}
|
|
106
|
+
sub {
|
|
107
|
+
bottom: -0.25em;
|
|
108
|
+
}
|
|
109
|
+
sup {
|
|
110
|
+
top: -0.5em;
|
|
111
|
+
}
|
|
112
|
+
table {
|
|
113
|
+
text-indent: 0;
|
|
114
|
+
border-color: inherit;
|
|
115
|
+
border-collapse: collapse;
|
|
116
|
+
}
|
|
117
|
+
:-moz-focusring {
|
|
118
|
+
outline: auto;
|
|
119
|
+
}
|
|
120
|
+
progress {
|
|
121
|
+
vertical-align: baseline;
|
|
122
|
+
}
|
|
123
|
+
summary {
|
|
124
|
+
display: list-item;
|
|
125
|
+
}
|
|
126
|
+
ol,
|
|
127
|
+
ul,
|
|
128
|
+
menu {
|
|
129
|
+
list-style: none;
|
|
130
|
+
}
|
|
131
|
+
img,
|
|
132
|
+
svg,
|
|
133
|
+
video,
|
|
134
|
+
canvas,
|
|
135
|
+
audio,
|
|
136
|
+
iframe,
|
|
137
|
+
embed,
|
|
138
|
+
object {
|
|
139
|
+
display: block;
|
|
140
|
+
vertical-align: middle;
|
|
141
|
+
}
|
|
142
|
+
img,
|
|
143
|
+
video {
|
|
144
|
+
max-width: 100%;
|
|
145
|
+
height: auto;
|
|
146
|
+
}
|
|
147
|
+
button,
|
|
148
|
+
input,
|
|
149
|
+
select,
|
|
150
|
+
optgroup,
|
|
151
|
+
textarea,
|
|
152
|
+
::file-selector-button {
|
|
153
|
+
font: inherit;
|
|
154
|
+
font-feature-settings: inherit;
|
|
155
|
+
font-variation-settings: inherit;
|
|
156
|
+
letter-spacing: inherit;
|
|
157
|
+
color: inherit;
|
|
158
|
+
border-radius: 0;
|
|
159
|
+
background-color: transparent;
|
|
160
|
+
opacity: 1;
|
|
161
|
+
}
|
|
162
|
+
:where(select:is([multiple], [size])) optgroup {
|
|
163
|
+
font-weight: bolder;
|
|
164
|
+
}
|
|
165
|
+
:where(select:is([multiple], [size])) optgroup option {
|
|
166
|
+
padding-inline-start: 20px;
|
|
167
|
+
}
|
|
168
|
+
::file-selector-button {
|
|
169
|
+
margin-inline-end: 4px;
|
|
170
|
+
}
|
|
171
|
+
::placeholder {
|
|
172
|
+
opacity: 1;
|
|
173
|
+
}
|
|
174
|
+
@supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {
|
|
175
|
+
::placeholder {
|
|
176
|
+
color: currentcolor;
|
|
177
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
178
|
+
color: color-mix(in oklab, currentcolor 50%, transparent);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
textarea {
|
|
183
|
+
resize: vertical;
|
|
184
|
+
}
|
|
185
|
+
::-webkit-search-decoration {
|
|
186
|
+
-webkit-appearance: none;
|
|
187
|
+
}
|
|
188
|
+
::-webkit-date-and-time-value {
|
|
189
|
+
min-height: 1lh;
|
|
190
|
+
text-align: inherit;
|
|
191
|
+
}
|
|
192
|
+
::-webkit-datetime-edit {
|
|
193
|
+
display: inline-flex;
|
|
194
|
+
}
|
|
195
|
+
::-webkit-datetime-edit-fields-wrapper {
|
|
196
|
+
padding: 0;
|
|
197
|
+
}
|
|
198
|
+
::-webkit-datetime-edit,
|
|
199
|
+
::-webkit-datetime-edit-year-field,
|
|
200
|
+
::-webkit-datetime-edit-month-field,
|
|
201
|
+
::-webkit-datetime-edit-day-field,
|
|
202
|
+
::-webkit-datetime-edit-hour-field,
|
|
203
|
+
::-webkit-datetime-edit-minute-field,
|
|
204
|
+
::-webkit-datetime-edit-second-field,
|
|
205
|
+
::-webkit-datetime-edit-millisecond-field,
|
|
206
|
+
::-webkit-datetime-edit-meridiem-field {
|
|
207
|
+
padding-block: 0;
|
|
208
|
+
}
|
|
209
|
+
::-webkit-calendar-picker-indicator {
|
|
210
|
+
line-height: 1;
|
|
211
|
+
}
|
|
212
|
+
:-moz-ui-invalid {
|
|
213
|
+
box-shadow: none;
|
|
214
|
+
}
|
|
215
|
+
button,
|
|
216
|
+
input:where([type=button], [type=reset], [type=submit]),
|
|
217
|
+
::file-selector-button {
|
|
218
|
+
appearance: button;
|
|
219
|
+
}
|
|
220
|
+
::-webkit-inner-spin-button,
|
|
221
|
+
::-webkit-outer-spin-button {
|
|
222
|
+
height: auto;
|
|
223
|
+
}
|
|
224
|
+
[hidden]:where(:not([hidden=until-found])) {
|
|
225
|
+
display: none !important;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
@layer utilities {
|
|
229
|
+
.rounded-lg {
|
|
230
|
+
border-radius: var(--radius-lg);
|
|
231
|
+
}
|
|
232
|
+
.rounded-md {
|
|
233
|
+
border-radius: var(--radius-md);
|
|
234
|
+
}
|
|
235
|
+
.border {
|
|
236
|
+
border-style: var(--tw-border-style);
|
|
237
|
+
border-width: 1px;
|
|
238
|
+
}
|
|
239
|
+
.border-solid {
|
|
240
|
+
--tw-border-style: solid;
|
|
241
|
+
border-style: solid;
|
|
242
|
+
}
|
|
243
|
+
.border-gray-200\/50 {
|
|
244
|
+
border-color: color-mix(in srgb, oklch(92.8% 0.006 264.531) 50%, transparent);
|
|
245
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
246
|
+
border-color: color-mix(in oklab, var(--color-gray-200) 50%, transparent);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
.bg-gray-200 {
|
|
250
|
+
background-color: var(--color-gray-200);
|
|
251
|
+
}
|
|
252
|
+
.bg-white {
|
|
253
|
+
background-color: var(--color-white);
|
|
254
|
+
}
|
|
255
|
+
.p-1\.5 {
|
|
256
|
+
padding: calc(var(--spacing) * 1.5);
|
|
257
|
+
}
|
|
258
|
+
.px-3 {
|
|
259
|
+
padding-inline: calc(var(--spacing) * 3);
|
|
260
|
+
}
|
|
261
|
+
.py-1 {
|
|
262
|
+
padding-block: calc(var(--spacing) * 1);
|
|
263
|
+
}
|
|
264
|
+
.text-center {
|
|
265
|
+
text-align: center;
|
|
266
|
+
}
|
|
267
|
+
.text-sm {
|
|
268
|
+
font-size: var(--text-sm);
|
|
269
|
+
line-height: var(--tw-leading, var(--text-sm--line-height));
|
|
270
|
+
}
|
|
271
|
+
.shadow-lg {
|
|
272
|
+
--tw-shadow: 0 10px 15px -3px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 4px 6px -4px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
|
|
273
|
+
box-shadow:
|
|
274
|
+
var(--tw-inset-shadow),
|
|
275
|
+
var(--tw-inset-ring-shadow),
|
|
276
|
+
var(--tw-ring-offset-shadow),
|
|
277
|
+
var(--tw-ring-shadow),
|
|
278
|
+
var(--tw-shadow);
|
|
279
|
+
}
|
|
280
|
+
.shadow-gray-50 {
|
|
281
|
+
--tw-shadow-color: oklch(98.5% 0.002 247.839);
|
|
282
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
283
|
+
--tw-shadow-color: color-mix(in oklab, var(--color-gray-50) var(--tw-shadow-alpha), transparent);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
.transition {
|
|
287
|
+
transition-property:
|
|
288
|
+
color,
|
|
289
|
+
background-color,
|
|
290
|
+
border-color,
|
|
291
|
+
outline-color,
|
|
292
|
+
text-decoration-color,
|
|
293
|
+
fill,
|
|
294
|
+
stroke,
|
|
295
|
+
--tw-gradient-from,
|
|
296
|
+
--tw-gradient-via,
|
|
297
|
+
--tw-gradient-to,
|
|
298
|
+
opacity,
|
|
299
|
+
box-shadow,
|
|
300
|
+
transform,
|
|
301
|
+
translate,
|
|
302
|
+
scale,
|
|
303
|
+
rotate,
|
|
304
|
+
filter,
|
|
305
|
+
-webkit-backdrop-filter,
|
|
306
|
+
backdrop-filter,
|
|
307
|
+
display,
|
|
308
|
+
content-visibility,
|
|
309
|
+
overlay,
|
|
310
|
+
pointer-events;
|
|
311
|
+
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
|
|
312
|
+
transition-duration: var(--tw-duration, var(--default-transition-duration));
|
|
313
|
+
}
|
|
314
|
+
.hover\:bg-gray-100 {
|
|
315
|
+
&:hover {
|
|
316
|
+
@media (hover: hover) {
|
|
317
|
+
background-color: var(--color-gray-100);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
.focus\:outline-none {
|
|
322
|
+
&:focus {
|
|
323
|
+
--tw-outline-style: none;
|
|
324
|
+
outline-style: none;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
.\[\&_\.tiptap\]\:min-h-\[200px\] {
|
|
328
|
+
& .tiptap {
|
|
329
|
+
min-height: 200px;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
.\[\&_\.tiptap\]\:p-\[10px_20px\] {
|
|
333
|
+
& .tiptap {
|
|
334
|
+
padding: 10px 20px;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
.\[\&_\.tiptap\]\:focus\:outline-none {
|
|
338
|
+
& .tiptap {
|
|
339
|
+
&:focus {
|
|
340
|
+
--tw-outline-style: none;
|
|
341
|
+
outline-style: none;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
@layer utilities {
|
|
347
|
+
button {
|
|
348
|
+
cursor: pointer;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
@property --tw-border-style { syntax: "*"; inherits: false; initial-value: solid; }
|
|
352
|
+
@property --tw-shadow { syntax: "*"; inherits: false; initial-value: 0 0 #0000; }
|
|
353
|
+
@property --tw-shadow-color { syntax: "*"; inherits: false; }
|
|
354
|
+
@property --tw-shadow-alpha { syntax: "<percentage>"; inherits: false; initial-value: 100%; }
|
|
355
|
+
@property --tw-inset-shadow { syntax: "*"; inherits: false; initial-value: 0 0 #0000; }
|
|
356
|
+
@property --tw-inset-shadow-color { syntax: "*"; inherits: false; }
|
|
357
|
+
@property --tw-inset-shadow-alpha { syntax: "<percentage>"; inherits: false; initial-value: 100%; }
|
|
358
|
+
@property --tw-ring-color { syntax: "*"; inherits: false; }
|
|
359
|
+
@property --tw-ring-shadow { syntax: "*"; inherits: false; initial-value: 0 0 #0000; }
|
|
360
|
+
@property --tw-inset-ring-color { syntax: "*"; inherits: false; }
|
|
361
|
+
@property --tw-inset-ring-shadow { syntax: "*"; inherits: false; initial-value: 0 0 #0000; }
|
|
362
|
+
@property --tw-ring-inset { syntax: "*"; inherits: false; }
|
|
363
|
+
@property --tw-ring-offset-width { syntax: "<length>"; inherits: false; initial-value: 0px; }
|
|
364
|
+
@property --tw-ring-offset-color { syntax: "*"; inherits: false; initial-value: #fff; }
|
|
365
|
+
@property --tw-ring-offset-shadow { syntax: "*"; inherits: false; initial-value: 0 0 #0000; }
|
|
366
|
+
@layer properties {
|
|
367
|
+
@supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
|
|
368
|
+
*,
|
|
369
|
+
::before,
|
|
370
|
+
::after,
|
|
371
|
+
::backdrop {
|
|
372
|
+
--tw-border-style: solid;
|
|
373
|
+
--tw-shadow: 0 0 #0000;
|
|
374
|
+
--tw-shadow-color: initial;
|
|
375
|
+
--tw-shadow-alpha: 100%;
|
|
376
|
+
--tw-inset-shadow: 0 0 #0000;
|
|
377
|
+
--tw-inset-shadow-color: initial;
|
|
378
|
+
--tw-inset-shadow-alpha: 100%;
|
|
379
|
+
--tw-ring-color: initial;
|
|
380
|
+
--tw-ring-shadow: 0 0 #0000;
|
|
381
|
+
--tw-inset-ring-color: initial;
|
|
382
|
+
--tw-inset-ring-shadow: 0 0 #0000;
|
|
383
|
+
--tw-ring-inset: initial;
|
|
384
|
+
--tw-ring-offset-width: 0px;
|
|
385
|
+
--tw-ring-offset-color: #fff;
|
|
386
|
+
--tw-ring-offset-shadow: 0 0 #0000;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/*! tailwindcss v4.1.16 | MIT License | https://tailwindcss.com */
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { Extensions, Mark } from '@tiptap/react';
|
|
4
|
+
import { Placement } from '@floating-ui/react';
|
|
5
|
+
|
|
6
|
+
interface Props$2 {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
extensions?: Extensions;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const Editor: ({ children, extensions, className }: Props$2) => react_jsx_runtime.JSX.Element;
|
|
12
|
+
|
|
13
|
+
interface Props$1 {
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
declare const Toolbar: ({ className }: Props$1) => react_jsx_runtime.JSX.Element | null;
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const Content: ({ className }: Props) => react_jsx_runtime.JSX.Element;
|
|
22
|
+
|
|
23
|
+
type BoldOptions = {
|
|
24
|
+
className?: string;
|
|
25
|
+
activeClassName?: string;
|
|
26
|
+
icon?: ReactNode;
|
|
27
|
+
style?: CSSProperties;
|
|
28
|
+
tooltip?: boolean | string;
|
|
29
|
+
tooltipClassName?: string;
|
|
30
|
+
tooltipPlacement?: Placement;
|
|
31
|
+
button: (args: {
|
|
32
|
+
options: BoldOptions;
|
|
33
|
+
}) => ReactNode;
|
|
34
|
+
};
|
|
35
|
+
declare const Bold: Mark<BoldOptions, any>;
|
|
36
|
+
|
|
37
|
+
export { Bold, Content, Editor, Toolbar };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { Extensions, Mark } from '@tiptap/react';
|
|
4
|
+
import { Placement } from '@floating-ui/react';
|
|
5
|
+
|
|
6
|
+
interface Props$2 {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
extensions?: Extensions;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const Editor: ({ children, extensions, className }: Props$2) => react_jsx_runtime.JSX.Element;
|
|
12
|
+
|
|
13
|
+
interface Props$1 {
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
declare const Toolbar: ({ className }: Props$1) => react_jsx_runtime.JSX.Element | null;
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const Content: ({ className }: Props) => react_jsx_runtime.JSX.Element;
|
|
22
|
+
|
|
23
|
+
type BoldOptions = {
|
|
24
|
+
className?: string;
|
|
25
|
+
activeClassName?: string;
|
|
26
|
+
icon?: ReactNode;
|
|
27
|
+
style?: CSSProperties;
|
|
28
|
+
tooltip?: boolean | string;
|
|
29
|
+
tooltipClassName?: string;
|
|
30
|
+
tooltipPlacement?: Placement;
|
|
31
|
+
button: (args: {
|
|
32
|
+
options: BoldOptions;
|
|
33
|
+
}) => ReactNode;
|
|
34
|
+
};
|
|
35
|
+
declare const Bold: Mark<BoldOptions, any>;
|
|
36
|
+
|
|
37
|
+
export { Bold, Content, Editor, Toolbar };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
60
|
+
var index_exports = {};
|
|
61
|
+
__export(index_exports, {
|
|
62
|
+
Bold: () => Bold,
|
|
63
|
+
Content: () => Content_default,
|
|
64
|
+
Editor: () => Editor_default,
|
|
65
|
+
Toolbar: () => Toolbar_default
|
|
66
|
+
});
|
|
67
|
+
module.exports = __toCommonJS(index_exports);
|
|
68
|
+
|
|
69
|
+
// src/lib/Editor.tsx
|
|
70
|
+
var import_react2 = require("react");
|
|
71
|
+
var import_react3 = require("@tiptap/react");
|
|
72
|
+
var import_extension_document = __toESM(require("@tiptap/extension-document"));
|
|
73
|
+
var import_extension_paragraph = __toESM(require("@tiptap/extension-paragraph"));
|
|
74
|
+
var import_extension_text = __toESM(require("@tiptap/extension-text"));
|
|
75
|
+
|
|
76
|
+
// src/lib/context/editor.context.tsx
|
|
77
|
+
var import_react = require("react");
|
|
78
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
79
|
+
var EditorContext = (0, import_react.createContext)({ editor: null });
|
|
80
|
+
var useEditor = () => {
|
|
81
|
+
const ctx = (0, import_react.useContext)(EditorContext);
|
|
82
|
+
if (!ctx) throw new Error("<Toolbar/> & <Content/> component must be used inside <Editor>...</Editor/>");
|
|
83
|
+
return ctx;
|
|
84
|
+
};
|
|
85
|
+
var EditorProvider = ({ children, value }) => {
|
|
86
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorContext.Provider, { value, children });
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/lib/Editor.tsx
|
|
90
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
91
|
+
var Editor = ({ children, extensions = [], className }) => {
|
|
92
|
+
const editor = (0, import_react3.useEditor)({
|
|
93
|
+
extensions: [import_extension_document.default, import_extension_paragraph.default, import_extension_text.default, ...extensions],
|
|
94
|
+
immediatelyRender: false
|
|
95
|
+
});
|
|
96
|
+
const value = (0, import_react2.useMemo)(() => ({ editor }), [editor]);
|
|
97
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EditorProvider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className, children }) });
|
|
98
|
+
};
|
|
99
|
+
var Editor_default = Editor;
|
|
100
|
+
|
|
101
|
+
// src/lib/Toolbar.tsx
|
|
102
|
+
var React = __toESM(require("react"));
|
|
103
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
104
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
105
|
+
var Toolbar = ({ className }) => {
|
|
106
|
+
const { editor } = useEditor();
|
|
107
|
+
if (!editor) return null;
|
|
108
|
+
const entries = editor.extensionManager.extensions.map((ext) => {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
const anyExt = ext;
|
|
111
|
+
const renderButton = ((_a = anyExt.options) == null ? void 0 : _a.button) || ((_c = (_b = anyExt.options) == null ? void 0 : _b.ui) == null ? void 0 : _c.button);
|
|
112
|
+
return renderButton ? { name: anyExt.name, renderButton, options: anyExt.options } : null;
|
|
113
|
+
}).filter(Boolean);
|
|
114
|
+
if (!entries.length) return null;
|
|
115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: (0, import_tailwind_merge.twMerge)("", className), children: entries.map(({ name, renderButton, options }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(React.Fragment, { children: renderButton({ editor, options }) }, name)) });
|
|
116
|
+
};
|
|
117
|
+
var Toolbar_default = Toolbar;
|
|
118
|
+
|
|
119
|
+
// src/lib/Content.tsx
|
|
120
|
+
var import_react4 = require("@tiptap/react");
|
|
121
|
+
var import_tailwind_merge2 = require("tailwind-merge");
|
|
122
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
123
|
+
var Content = ({ className }) => {
|
|
124
|
+
const { editor } = useEditor();
|
|
125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.EditorContent, { editor, className: (0, import_tailwind_merge2.twMerge)("focus:outline-none [&_.tiptap]:focus:outline-none [&_.tiptap]:min-h-[200px] [&_.tiptap]:p-[10px_20px]", className) });
|
|
126
|
+
};
|
|
127
|
+
var Content_default = Content;
|
|
128
|
+
|
|
129
|
+
// src/lib/extensions/Bold.tsx
|
|
130
|
+
var import_extension_bold = __toESM(require("@tiptap/extension-bold"));
|
|
131
|
+
|
|
132
|
+
// src/lib/components/BoldComponent.tsx
|
|
133
|
+
var import_tailwind_merge4 = require("tailwind-merge");
|
|
134
|
+
|
|
135
|
+
// src/lib/icon/BoldIcon.tsx
|
|
136
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
137
|
+
var BoldIcon = (_a) => {
|
|
138
|
+
var _b = _a, {
|
|
139
|
+
size = 17,
|
|
140
|
+
className
|
|
141
|
+
} = _b, props = __objRest(_b, [
|
|
142
|
+
"size",
|
|
143
|
+
"className"
|
|
144
|
+
]);
|
|
145
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
146
|
+
"svg",
|
|
147
|
+
__spreadProps(__spreadValues({
|
|
148
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
149
|
+
viewBox: "0 0 24 24",
|
|
150
|
+
fill: "none",
|
|
151
|
+
stroke: "currentColor",
|
|
152
|
+
strokeWidth: 2,
|
|
153
|
+
strokeLinecap: "round",
|
|
154
|
+
strokeLinejoin: "round",
|
|
155
|
+
width: size,
|
|
156
|
+
height: size,
|
|
157
|
+
className
|
|
158
|
+
}, props), {
|
|
159
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" })
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
var BoldIcon_default = BoldIcon;
|
|
164
|
+
|
|
165
|
+
// src/lib/components/_com/Tooltip.tsx
|
|
166
|
+
var import_react5 = require("react");
|
|
167
|
+
var import_react6 = require("@floating-ui/react");
|
|
168
|
+
var import_react7 = require("motion/react");
|
|
169
|
+
var import_tailwind_merge3 = require("tailwind-merge");
|
|
170
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
171
|
+
var Tooltip = ({ placement = "top", children, content, className }) => {
|
|
172
|
+
const [open, setOpen] = (0, import_react5.useState)(false);
|
|
173
|
+
const { x, y, refs, strategy, context, placement: resolvedPlacement } = (0, import_react6.useFloating)({
|
|
174
|
+
open,
|
|
175
|
+
onOpenChange: setOpen,
|
|
176
|
+
placement,
|
|
177
|
+
middleware: [(0, import_react6.offset)(8), (0, import_react6.flip)(), (0, import_react6.shift)({ padding: 8 })],
|
|
178
|
+
whileElementsMounted: import_react6.autoUpdate
|
|
179
|
+
});
|
|
180
|
+
const hover = (0, import_react6.useHover)(context);
|
|
181
|
+
const dismiss = (0, import_react6.useDismiss)(context);
|
|
182
|
+
const { getReferenceProps, getFloatingProps } = (0, import_react6.useInteractions)([hover, dismiss]);
|
|
183
|
+
const id = (0, import_react5.useId)();
|
|
184
|
+
function mergeRefs(...refsToMerge) {
|
|
185
|
+
return (node) => {
|
|
186
|
+
for (const r of refsToMerge) {
|
|
187
|
+
if (!r) continue;
|
|
188
|
+
if (typeof r === "function") r(node);
|
|
189
|
+
else r.current = node;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const side = resolvedPlacement.split("-")[0];
|
|
194
|
+
const enterOffset = 6;
|
|
195
|
+
const getInitial = () => {
|
|
196
|
+
switch (side) {
|
|
197
|
+
case "top":
|
|
198
|
+
return { opacity: 0, y: enterOffset };
|
|
199
|
+
case "bottom":
|
|
200
|
+
return { opacity: 0, y: -enterOffset };
|
|
201
|
+
case "left":
|
|
202
|
+
return { opacity: 0, x: enterOffset };
|
|
203
|
+
case "right":
|
|
204
|
+
return { opacity: 0, x: -enterOffset };
|
|
205
|
+
default:
|
|
206
|
+
return { opacity: 0 };
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
const getExit = () => __spreadProps(__spreadValues({}, getInitial()), { opacity: 0 });
|
|
210
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react5.Fragment, { children: [
|
|
211
|
+
(0, import_react5.isValidElement)(children) ? (0, import_react5.cloneElement)(children, __spreadProps(__spreadValues({}, getReferenceProps({
|
|
212
|
+
onFocus: () => setOpen(true),
|
|
213
|
+
onBlur: () => setOpen(false),
|
|
214
|
+
"aria-describedby": open ? id : void 0
|
|
215
|
+
})), {
|
|
216
|
+
ref: mergeRefs(children.ref, refs.setReference)
|
|
217
|
+
})) : children,
|
|
218
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react6.FloatingPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react7.AnimatePresence, { children: open && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
219
|
+
import_react7.motion.div,
|
|
220
|
+
__spreadProps(__spreadValues({
|
|
221
|
+
ref: refs.setFloating
|
|
222
|
+
}, getFloatingProps({
|
|
223
|
+
role: "tooltip",
|
|
224
|
+
id,
|
|
225
|
+
style: {
|
|
226
|
+
position: strategy,
|
|
227
|
+
top: y != null ? y : 0,
|
|
228
|
+
left: x != null ? x : 0,
|
|
229
|
+
pointerEvents: "none"
|
|
230
|
+
}
|
|
231
|
+
})), {
|
|
232
|
+
initial: getInitial(),
|
|
233
|
+
animate: { opacity: 1, x: 0, y: 0, scale: 1 },
|
|
234
|
+
exit: getExit(),
|
|
235
|
+
transition: { type: "spring", stiffness: 420, damping: 30, mass: 0.6 },
|
|
236
|
+
className: (0, import_tailwind_merge3.twMerge)("bg-white border border-solid border-gray-200/50 py-1 px-3 rounded-lg text-sm shadow-lg shadow-gray-50 text-center", className),
|
|
237
|
+
children: content
|
|
238
|
+
}),
|
|
239
|
+
"tooltip"
|
|
240
|
+
) }) })
|
|
241
|
+
] });
|
|
242
|
+
};
|
|
243
|
+
var Tooltip_default = Tooltip;
|
|
244
|
+
|
|
245
|
+
// src/lib/components/BoldComponent.tsx
|
|
246
|
+
var import_react8 = require("@tiptap/react");
|
|
247
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
248
|
+
var BoldComponent = ({ className, activeClassName, icon, style, tooltip = true, tooltipClassName, tooltipPlacement }) => {
|
|
249
|
+
const { editor } = useEditor();
|
|
250
|
+
const editorState = (0, import_react8.useEditorState)({
|
|
251
|
+
editor,
|
|
252
|
+
selector: ({ editor: editor2 }) => ({ isActive: (editor2 == null ? void 0 : editor2.isActive("bold")) || false })
|
|
253
|
+
});
|
|
254
|
+
const tooltipContent = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { children: [
|
|
255
|
+
typeof tooltip === "string" ? tooltip : "Bold",
|
|
256
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("br", {}),
|
|
257
|
+
"\u2318 + B"
|
|
258
|
+
] });
|
|
259
|
+
const btn = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
260
|
+
"button",
|
|
261
|
+
{
|
|
262
|
+
onClick: () => editor == null ? void 0 : editor.chain().focus().toggleBold().run(),
|
|
263
|
+
className: (0, import_tailwind_merge4.twMerge)(
|
|
264
|
+
"p-1.5 rounded-md",
|
|
265
|
+
(editorState == null ? void 0 : editorState.isActive) ? "bg-gray-200" : "hover:bg-gray-100",
|
|
266
|
+
className,
|
|
267
|
+
(editorState == null ? void 0 : editorState.isActive) ? activeClassName : "hover:bg-gray-100"
|
|
268
|
+
),
|
|
269
|
+
style,
|
|
270
|
+
children: icon != null ? icon : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BoldIcon_default, {})
|
|
271
|
+
}
|
|
272
|
+
);
|
|
273
|
+
if (tooltip === false) return btn;
|
|
274
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
275
|
+
Tooltip_default,
|
|
276
|
+
{
|
|
277
|
+
content: tooltipContent,
|
|
278
|
+
className: tooltipClassName,
|
|
279
|
+
placement: tooltipPlacement,
|
|
280
|
+
children: btn
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
};
|
|
284
|
+
var BoldComponent_default = BoldComponent;
|
|
285
|
+
|
|
286
|
+
// src/lib/extensions/Bold.tsx
|
|
287
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
288
|
+
var Bold = import_extension_bold.default.extend({
|
|
289
|
+
addOptions() {
|
|
290
|
+
var _a;
|
|
291
|
+
return __spreadProps(__spreadValues({}, (_a = this.parent) == null ? void 0 : _a.call(this)), {
|
|
292
|
+
button: ({ options }) => {
|
|
293
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
294
|
+
BoldComponent_default,
|
|
295
|
+
{
|
|
296
|
+
className: options.className,
|
|
297
|
+
icon: options.icon,
|
|
298
|
+
style: options.style,
|
|
299
|
+
activeClassName: options.activeClassName,
|
|
300
|
+
tooltip: options.tooltip,
|
|
301
|
+
tooltipClassName: options.tooltipClassName,
|
|
302
|
+
tooltipPlacement: options.tooltipPlacement
|
|
303
|
+
}
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
310
|
+
0 && (module.exports = {
|
|
311
|
+
Bold,
|
|
312
|
+
Content,
|
|
313
|
+
Editor,
|
|
314
|
+
Toolbar
|
|
315
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/lib/Editor.tsx
|
|
34
|
+
import { useMemo } from "react";
|
|
35
|
+
import { useEditor as useEditor2 } from "@tiptap/react";
|
|
36
|
+
import Document from "@tiptap/extension-document";
|
|
37
|
+
import Paragraph from "@tiptap/extension-paragraph";
|
|
38
|
+
import Text from "@tiptap/extension-text";
|
|
39
|
+
|
|
40
|
+
// src/lib/context/editor.context.tsx
|
|
41
|
+
import { createContext, useContext } from "react";
|
|
42
|
+
import { jsx } from "react/jsx-runtime";
|
|
43
|
+
var EditorContext = createContext({ editor: null });
|
|
44
|
+
var useEditor = () => {
|
|
45
|
+
const ctx = useContext(EditorContext);
|
|
46
|
+
if (!ctx) throw new Error("<Toolbar/> & <Content/> component must be used inside <Editor>...</Editor/>");
|
|
47
|
+
return ctx;
|
|
48
|
+
};
|
|
49
|
+
var EditorProvider = ({ children, value }) => {
|
|
50
|
+
return /* @__PURE__ */ jsx(EditorContext.Provider, { value, children });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/lib/Editor.tsx
|
|
54
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
55
|
+
var Editor = ({ children, extensions = [], className }) => {
|
|
56
|
+
const editor = useEditor2({
|
|
57
|
+
extensions: [Document, Paragraph, Text, ...extensions],
|
|
58
|
+
immediatelyRender: false
|
|
59
|
+
});
|
|
60
|
+
const value = useMemo(() => ({ editor }), [editor]);
|
|
61
|
+
return /* @__PURE__ */ jsx2(EditorProvider, { value, children: /* @__PURE__ */ jsx2("div", { className, children }) });
|
|
62
|
+
};
|
|
63
|
+
var Editor_default = Editor;
|
|
64
|
+
|
|
65
|
+
// src/lib/Toolbar.tsx
|
|
66
|
+
import * as React from "react";
|
|
67
|
+
import { twMerge } from "tailwind-merge";
|
|
68
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
69
|
+
var Toolbar = ({ className }) => {
|
|
70
|
+
const { editor } = useEditor();
|
|
71
|
+
if (!editor) return null;
|
|
72
|
+
const entries = editor.extensionManager.extensions.map((ext) => {
|
|
73
|
+
var _a, _b, _c;
|
|
74
|
+
const anyExt = ext;
|
|
75
|
+
const renderButton = ((_a = anyExt.options) == null ? void 0 : _a.button) || ((_c = (_b = anyExt.options) == null ? void 0 : _b.ui) == null ? void 0 : _c.button);
|
|
76
|
+
return renderButton ? { name: anyExt.name, renderButton, options: anyExt.options } : null;
|
|
77
|
+
}).filter(Boolean);
|
|
78
|
+
if (!entries.length) return null;
|
|
79
|
+
return /* @__PURE__ */ jsx3("div", { className: twMerge("", className), children: entries.map(({ name, renderButton, options }) => /* @__PURE__ */ jsx3(React.Fragment, { children: renderButton({ editor, options }) }, name)) });
|
|
80
|
+
};
|
|
81
|
+
var Toolbar_default = Toolbar;
|
|
82
|
+
|
|
83
|
+
// src/lib/Content.tsx
|
|
84
|
+
import { EditorContent } from "@tiptap/react";
|
|
85
|
+
import { twMerge as twMerge2 } from "tailwind-merge";
|
|
86
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
87
|
+
var Content = ({ className }) => {
|
|
88
|
+
const { editor } = useEditor();
|
|
89
|
+
return /* @__PURE__ */ jsx4(EditorContent, { editor, className: twMerge2("focus:outline-none [&_.tiptap]:focus:outline-none [&_.tiptap]:min-h-[200px] [&_.tiptap]:p-[10px_20px]", className) });
|
|
90
|
+
};
|
|
91
|
+
var Content_default = Content;
|
|
92
|
+
|
|
93
|
+
// src/lib/extensions/Bold.tsx
|
|
94
|
+
import TiptapBold from "@tiptap/extension-bold";
|
|
95
|
+
|
|
96
|
+
// src/lib/components/BoldComponent.tsx
|
|
97
|
+
import { twMerge as twMerge4 } from "tailwind-merge";
|
|
98
|
+
|
|
99
|
+
// src/lib/icon/BoldIcon.tsx
|
|
100
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
101
|
+
var BoldIcon = (_a) => {
|
|
102
|
+
var _b = _a, {
|
|
103
|
+
size = 17,
|
|
104
|
+
className
|
|
105
|
+
} = _b, props = __objRest(_b, [
|
|
106
|
+
"size",
|
|
107
|
+
"className"
|
|
108
|
+
]);
|
|
109
|
+
return /* @__PURE__ */ jsx5(
|
|
110
|
+
"svg",
|
|
111
|
+
__spreadProps(__spreadValues({
|
|
112
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
113
|
+
viewBox: "0 0 24 24",
|
|
114
|
+
fill: "none",
|
|
115
|
+
stroke: "currentColor",
|
|
116
|
+
strokeWidth: 2,
|
|
117
|
+
strokeLinecap: "round",
|
|
118
|
+
strokeLinejoin: "round",
|
|
119
|
+
width: size,
|
|
120
|
+
height: size,
|
|
121
|
+
className
|
|
122
|
+
}, props), {
|
|
123
|
+
children: /* @__PURE__ */ jsx5("path", { d: "M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" })
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
var BoldIcon_default = BoldIcon;
|
|
128
|
+
|
|
129
|
+
// src/lib/components/_com/Tooltip.tsx
|
|
130
|
+
import { useState, Fragment as Fragment2, cloneElement, isValidElement, useId } from "react";
|
|
131
|
+
import { useFloating, offset, flip, shift, autoUpdate, useInteractions, useHover, useDismiss, FloatingPortal } from "@floating-ui/react";
|
|
132
|
+
import { AnimatePresence, motion } from "motion/react";
|
|
133
|
+
import { twMerge as twMerge3 } from "tailwind-merge";
|
|
134
|
+
import { jsx as jsx6, jsxs } from "react/jsx-runtime";
|
|
135
|
+
var Tooltip = ({ placement = "top", children, content, className }) => {
|
|
136
|
+
const [open, setOpen] = useState(false);
|
|
137
|
+
const { x, y, refs, strategy, context, placement: resolvedPlacement } = useFloating({
|
|
138
|
+
open,
|
|
139
|
+
onOpenChange: setOpen,
|
|
140
|
+
placement,
|
|
141
|
+
middleware: [offset(8), flip(), shift({ padding: 8 })],
|
|
142
|
+
whileElementsMounted: autoUpdate
|
|
143
|
+
});
|
|
144
|
+
const hover = useHover(context);
|
|
145
|
+
const dismiss = useDismiss(context);
|
|
146
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([hover, dismiss]);
|
|
147
|
+
const id = useId();
|
|
148
|
+
function mergeRefs(...refsToMerge) {
|
|
149
|
+
return (node) => {
|
|
150
|
+
for (const r of refsToMerge) {
|
|
151
|
+
if (!r) continue;
|
|
152
|
+
if (typeof r === "function") r(node);
|
|
153
|
+
else r.current = node;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const side = resolvedPlacement.split("-")[0];
|
|
158
|
+
const enterOffset = 6;
|
|
159
|
+
const getInitial = () => {
|
|
160
|
+
switch (side) {
|
|
161
|
+
case "top":
|
|
162
|
+
return { opacity: 0, y: enterOffset };
|
|
163
|
+
case "bottom":
|
|
164
|
+
return { opacity: 0, y: -enterOffset };
|
|
165
|
+
case "left":
|
|
166
|
+
return { opacity: 0, x: enterOffset };
|
|
167
|
+
case "right":
|
|
168
|
+
return { opacity: 0, x: -enterOffset };
|
|
169
|
+
default:
|
|
170
|
+
return { opacity: 0 };
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const getExit = () => __spreadProps(__spreadValues({}, getInitial()), { opacity: 0 });
|
|
174
|
+
return /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
175
|
+
isValidElement(children) ? cloneElement(children, __spreadProps(__spreadValues({}, getReferenceProps({
|
|
176
|
+
onFocus: () => setOpen(true),
|
|
177
|
+
onBlur: () => setOpen(false),
|
|
178
|
+
"aria-describedby": open ? id : void 0
|
|
179
|
+
})), {
|
|
180
|
+
ref: mergeRefs(children.ref, refs.setReference)
|
|
181
|
+
})) : children,
|
|
182
|
+
/* @__PURE__ */ jsx6(FloatingPortal, { children: /* @__PURE__ */ jsx6(AnimatePresence, { children: open && /* @__PURE__ */ jsx6(
|
|
183
|
+
motion.div,
|
|
184
|
+
__spreadProps(__spreadValues({
|
|
185
|
+
ref: refs.setFloating
|
|
186
|
+
}, getFloatingProps({
|
|
187
|
+
role: "tooltip",
|
|
188
|
+
id,
|
|
189
|
+
style: {
|
|
190
|
+
position: strategy,
|
|
191
|
+
top: y != null ? y : 0,
|
|
192
|
+
left: x != null ? x : 0,
|
|
193
|
+
pointerEvents: "none"
|
|
194
|
+
}
|
|
195
|
+
})), {
|
|
196
|
+
initial: getInitial(),
|
|
197
|
+
animate: { opacity: 1, x: 0, y: 0, scale: 1 },
|
|
198
|
+
exit: getExit(),
|
|
199
|
+
transition: { type: "spring", stiffness: 420, damping: 30, mass: 0.6 },
|
|
200
|
+
className: twMerge3("bg-white border border-solid border-gray-200/50 py-1 px-3 rounded-lg text-sm shadow-lg shadow-gray-50 text-center", className),
|
|
201
|
+
children: content
|
|
202
|
+
}),
|
|
203
|
+
"tooltip"
|
|
204
|
+
) }) })
|
|
205
|
+
] });
|
|
206
|
+
};
|
|
207
|
+
var Tooltip_default = Tooltip;
|
|
208
|
+
|
|
209
|
+
// src/lib/components/BoldComponent.tsx
|
|
210
|
+
import { useEditorState } from "@tiptap/react";
|
|
211
|
+
import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
212
|
+
var BoldComponent = ({ className, activeClassName, icon, style, tooltip = true, tooltipClassName, tooltipPlacement }) => {
|
|
213
|
+
const { editor } = useEditor();
|
|
214
|
+
const editorState = useEditorState({
|
|
215
|
+
editor,
|
|
216
|
+
selector: ({ editor: editor2 }) => ({ isActive: (editor2 == null ? void 0 : editor2.isActive("bold")) || false })
|
|
217
|
+
});
|
|
218
|
+
const tooltipContent = /* @__PURE__ */ jsxs2("p", { children: [
|
|
219
|
+
typeof tooltip === "string" ? tooltip : "Bold",
|
|
220
|
+
/* @__PURE__ */ jsx7("br", {}),
|
|
221
|
+
"\u2318 + B"
|
|
222
|
+
] });
|
|
223
|
+
const btn = /* @__PURE__ */ jsx7(
|
|
224
|
+
"button",
|
|
225
|
+
{
|
|
226
|
+
onClick: () => editor == null ? void 0 : editor.chain().focus().toggleBold().run(),
|
|
227
|
+
className: twMerge4(
|
|
228
|
+
"p-1.5 rounded-md",
|
|
229
|
+
(editorState == null ? void 0 : editorState.isActive) ? "bg-gray-200" : "hover:bg-gray-100",
|
|
230
|
+
className,
|
|
231
|
+
(editorState == null ? void 0 : editorState.isActive) ? activeClassName : "hover:bg-gray-100"
|
|
232
|
+
),
|
|
233
|
+
style,
|
|
234
|
+
children: icon != null ? icon : /* @__PURE__ */ jsx7(BoldIcon_default, {})
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
if (tooltip === false) return btn;
|
|
238
|
+
return /* @__PURE__ */ jsx7(
|
|
239
|
+
Tooltip_default,
|
|
240
|
+
{
|
|
241
|
+
content: tooltipContent,
|
|
242
|
+
className: tooltipClassName,
|
|
243
|
+
placement: tooltipPlacement,
|
|
244
|
+
children: btn
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
};
|
|
248
|
+
var BoldComponent_default = BoldComponent;
|
|
249
|
+
|
|
250
|
+
// src/lib/extensions/Bold.tsx
|
|
251
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
252
|
+
var Bold = TiptapBold.extend({
|
|
253
|
+
addOptions() {
|
|
254
|
+
var _a;
|
|
255
|
+
return __spreadProps(__spreadValues({}, (_a = this.parent) == null ? void 0 : _a.call(this)), {
|
|
256
|
+
button: ({ options }) => {
|
|
257
|
+
return /* @__PURE__ */ jsx8(
|
|
258
|
+
BoldComponent_default,
|
|
259
|
+
{
|
|
260
|
+
className: options.className,
|
|
261
|
+
icon: options.icon,
|
|
262
|
+
style: options.style,
|
|
263
|
+
activeClassName: options.activeClassName,
|
|
264
|
+
tooltip: options.tooltip,
|
|
265
|
+
tooltipClassName: options.tooltipClassName,
|
|
266
|
+
tooltipPlacement: options.tooltipPlacement
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
export {
|
|
274
|
+
Bold,
|
|
275
|
+
Content_default as Content,
|
|
276
|
+
Editor_default as Editor,
|
|
277
|
+
Toolbar_default as Toolbar
|
|
278
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ritext",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Ritext is a modern WYSIWYG rich text editor built with Tailwind CSS, powered by Tiptap. It offers a customizable UI and functional layer that lets you design your own editor controls and toolbars with clean, composable React components—no heavy UI, no extra dependencies beyond Tiptap.",
|
|
5
|
+
"homepage": "https://ritext.vercel.app/",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "Siam Ahnaf",
|
|
14
|
+
"email": "mail@siamahnaf.com",
|
|
15
|
+
"url": "https://www.siamahnaf.com"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"ritext",
|
|
20
|
+
"tiptap",
|
|
21
|
+
"tiptap-react",
|
|
22
|
+
"react",
|
|
23
|
+
"rich-text-editor",
|
|
24
|
+
"wysiwyg",
|
|
25
|
+
"headless-editor",
|
|
26
|
+
"text-editor",
|
|
27
|
+
"tailwindcss",
|
|
28
|
+
"tailwind",
|
|
29
|
+
"editor-kit",
|
|
30
|
+
"editor-toolbar",
|
|
31
|
+
"editor-controls",
|
|
32
|
+
"markdown-editor",
|
|
33
|
+
"content-editor",
|
|
34
|
+
"react-editor",
|
|
35
|
+
"headless-ui",
|
|
36
|
+
"functional-editor",
|
|
37
|
+
"customizable-editor",
|
|
38
|
+
"react-components",
|
|
39
|
+
"frontend-editor"
|
|
40
|
+
],
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"directory": "https://github.com/siamahnaf/ritext",
|
|
44
|
+
"url": "https://github.com/siamahnaf/ritext"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@tailwindcss/postcss": "^4.1.16",
|
|
48
|
+
"@types/node": "^24",
|
|
49
|
+
"@types/react": "^19",
|
|
50
|
+
"@types/react-dom": "^19",
|
|
51
|
+
"eslint": "^9",
|
|
52
|
+
"postcss": "^8.5.6",
|
|
53
|
+
"react": "^19.2.0",
|
|
54
|
+
"react-dom": "^19.2.0",
|
|
55
|
+
"tailwindcss": "^4.1.16",
|
|
56
|
+
"tsup": "^8.5.0",
|
|
57
|
+
"turbo": "^2.5.8",
|
|
58
|
+
"typescript": "^5.9.3"
|
|
8
59
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@floating-ui/react": "^0.27.16",
|
|
62
|
+
"@tiptap/extension-bold": "^3.7.2",
|
|
63
|
+
"@tiptap/extension-document": "^3.7.2",
|
|
64
|
+
"@tiptap/extension-italic": "^3.7.2",
|
|
65
|
+
"@tiptap/extension-paragraph": "^3.7.2",
|
|
66
|
+
"@tiptap/extension-text": "^3.7.2",
|
|
67
|
+
"@tiptap/pm": "^3.7.2",
|
|
68
|
+
"@tiptap/react": "^3.7.2",
|
|
69
|
+
"@tiptap/starter-kit": "^3.7.2",
|
|
70
|
+
"motion": "^12.23.24",
|
|
71
|
+
"tailwind-merge": "^3.3.1"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"react": "^19",
|
|
75
|
+
"react-dom": "^19"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
79
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
80
|
+
}
|
|
11
81
|
}
|