@notum-cz/strapi-plugin-tiptap-editor 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,7 +88,12 @@
|
|
|
88
88
|
- [Links](#links)
|
|
89
89
|
- [Tables](#tables)
|
|
90
90
|
- [Text Alignment](#text-alignment)
|
|
91
|
+
- [Text Color \& Highlight Color](#text-color--highlight-color)
|
|
91
92
|
- [Images](#images)
|
|
93
|
+
- [Rendering images on the frontend](#rendering-images-on-the-frontend)
|
|
94
|
+
- [Theme](#theme)
|
|
95
|
+
- [Colors](#colors)
|
|
96
|
+
- [Custom Stylesheet](#custom-stylesheet)
|
|
92
97
|
- [Configuration Reference](#configuration-reference)
|
|
93
98
|
- [Feature Values](#feature-values)
|
|
94
99
|
- [Full Preset Example](#full-preset-example)
|
|
@@ -393,20 +398,40 @@ Enables all four alignment buttons (left, center, right, justify).
|
|
|
393
398
|
}
|
|
394
399
|
```
|
|
395
400
|
|
|
401
|
+
### Text Color & Highlight Color
|
|
402
|
+
|
|
403
|
+
| Key | Description | Toolbar |
|
|
404
|
+
| ---------------- | --------------------------------- | ---------------------- |
|
|
405
|
+
| `textColor` | Change the color of selected text | Font color picker |
|
|
406
|
+
| `highlightColor` | Apply a background highlight | Highlight color picker |
|
|
407
|
+
|
|
408
|
+
Both features use a color picker popover that displays the colors defined in the [theme configuration](#colors). If no colors are configured, the buttons will not appear.
|
|
409
|
+
|
|
410
|
+
```ts
|
|
411
|
+
{
|
|
412
|
+
textColor: true,
|
|
413
|
+
highlightColor: true,
|
|
414
|
+
}
|
|
415
|
+
```
|
|
416
|
+
|
|
396
417
|
### Images
|
|
397
418
|
|
|
398
|
-
| Key | Description | Toolbar
|
|
399
|
-
| -------------- | -------------------------------- |
|
|
400
|
-
| `mediaLibrary` | Images from Strapi Media Library | Image button + alt text popover + alignment |
|
|
419
|
+
| Key | Description | Toolbar |
|
|
420
|
+
| -------------- | -------------------------------- | --------------------------------------------------------- |
|
|
421
|
+
| `mediaLibrary` | Images from Strapi Media Library | Image button + alt text popover + alignment + resize handle |
|
|
401
422
|
|
|
402
423
|
Enables image insertion from the Strapi Media Library. When enabled, the toolbar shows an image button that opens the Media Library picker. After selecting an image:
|
|
403
424
|
|
|
404
425
|
- The image appears in the editor at its natural size (constrained to editor width)
|
|
405
426
|
- Alt text is prefilled from the asset's `alternativeText` metadata
|
|
406
|
-
- Clicking a selected image opens a popover
|
|
407
|
-
- Three alignment buttons (left, center, right)
|
|
427
|
+
- Clicking a selected image opens a popover with:
|
|
428
|
+
- Three **alignment** buttons (left, center, right)
|
|
429
|
+
- **Width** and **Height** inputs (in pixels) for precise sizing
|
|
430
|
+
- A **reset** button to restore the original dimensions
|
|
431
|
+
- **Alt text** input and a **delete** button
|
|
432
|
+
- A **resize handle** (blue dot) appears at the bottom-right corner on hover — drag it to resize the image
|
|
408
433
|
|
|
409
|
-
The image stores
|
|
434
|
+
The image stores the URL (`src`), Strapi asset ID (`data-asset-id`), alignment (`data-align`), and dimensions (`width`, `height`) in the Tiptap JSON output.
|
|
410
435
|
|
|
411
436
|
**Content safety:** If you remove `mediaLibrary` from a preset, existing images in content are preserved and rendered read-only — they are never silently deleted.
|
|
412
437
|
|
|
@@ -416,6 +441,152 @@ The image stores both the URL (`src`) and the Strapi asset ID (`data-asset-id`)
|
|
|
416
441
|
}
|
|
417
442
|
```
|
|
418
443
|
|
|
444
|
+
**Resize** is configured through the `resize` key inside `mediaLibrary`. The options match the standard `@tiptap/extension-image` `resize` configuration. When `resize` is omitted or set to `false`, the resize handle and dimension controls are hidden.
|
|
445
|
+
|
|
446
|
+
```ts
|
|
447
|
+
{
|
|
448
|
+
mediaLibrary: {
|
|
449
|
+
resize: {
|
|
450
|
+
enabled: true,
|
|
451
|
+
alwaysPreserveAspectRatio: true,
|
|
452
|
+
minWidth: 50,
|
|
453
|
+
minHeight: 50,
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
| Option | Default | Description |
|
|
460
|
+
| ----------------------------------- | ------- | ----------------------------------------------------- |
|
|
461
|
+
| `resize` | _none_ | Set to `false` or omit to disable resize entirely |
|
|
462
|
+
| `resize.enabled` | `true` | Enable or disable resize when the object is present |
|
|
463
|
+
| `resize.alwaysPreserveAspectRatio` | `true` | Lock aspect ratio when resizing or editing dimensions |
|
|
464
|
+
| `resize.minWidth` | `50` | Minimum allowed width in pixels |
|
|
465
|
+
| `resize.minHeight` | `50` | Minimum allowed height in pixels |
|
|
466
|
+
|
|
467
|
+
#### Rendering images on the frontend
|
|
468
|
+
|
|
469
|
+
The plugin stores content as **Tiptap/ProseMirror JSON**. The `width`, `height`, `src`, `alt`, and `title` attributes are standard and will render automatically with `@tiptap/extension-image`. However, the custom `data-align` and `data-asset-id` attributes require extending the Image extension on your frontend:
|
|
470
|
+
|
|
471
|
+
```ts
|
|
472
|
+
import { generateHTML } from '@tiptap/html';
|
|
473
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
474
|
+
import Image from '@tiptap/extension-image';
|
|
475
|
+
|
|
476
|
+
// Extend with the custom attributes used by this plugin
|
|
477
|
+
const StrapiImage = Image.extend({
|
|
478
|
+
addAttributes() {
|
|
479
|
+
return {
|
|
480
|
+
...this.parent?.(),
|
|
481
|
+
'data-align': { default: null },
|
|
482
|
+
'data-asset-id': { default: null },
|
|
483
|
+
};
|
|
484
|
+
},
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// Convert the JSON from the Strapi API to HTML
|
|
488
|
+
const html = generateHTML(apiResponse.content, [
|
|
489
|
+
StarterKit,
|
|
490
|
+
StrapiImage,
|
|
491
|
+
// ...other extensions you use
|
|
492
|
+
]);
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
Then add CSS for alignment on your frontend:
|
|
496
|
+
|
|
497
|
+
```css
|
|
498
|
+
img[data-align="center"] {
|
|
499
|
+
display: block;
|
|
500
|
+
margin-left: auto;
|
|
501
|
+
margin-right: auto;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
img[data-align="right"] {
|
|
505
|
+
display: block;
|
|
506
|
+
margin-left: auto;
|
|
507
|
+
margin-right: 0;
|
|
508
|
+
}
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## Theme
|
|
512
|
+
|
|
513
|
+
The `theme` key in the plugin config lets you define colors for the color pickers and inject custom CSS into the editor.
|
|
514
|
+
|
|
515
|
+
### Colors
|
|
516
|
+
|
|
517
|
+
Define a `colors` array to populate the text color and highlight color pickers. Each entry needs a `label` (shown as a tooltip) and a `color` value (hex, rgb, rgba, hsl, hsla, or CSS variable).
|
|
518
|
+
|
|
519
|
+
```ts
|
|
520
|
+
// config/plugins.ts
|
|
521
|
+
|
|
522
|
+
export default () => ({
|
|
523
|
+
'tiptap-editor': {
|
|
524
|
+
config: {
|
|
525
|
+
theme: {
|
|
526
|
+
colors: [
|
|
527
|
+
{ label: 'Black', color: '#000000' },
|
|
528
|
+
{ label: 'Dark gray', color: '#4A4A4A' },
|
|
529
|
+
{ label: 'Red', color: '#E53E3E' },
|
|
530
|
+
{ label: 'Orange', color: '#DD6B20' },
|
|
531
|
+
{ label: 'Blue', color: '#3182CE' },
|
|
532
|
+
{ label: 'Green', color: '#38A169' },
|
|
533
|
+
{ label: 'Brand primary', color: 'var(--color-primary)' },
|
|
534
|
+
],
|
|
535
|
+
},
|
|
536
|
+
presets: {
|
|
537
|
+
blog: {
|
|
538
|
+
bold: true,
|
|
539
|
+
italic: true,
|
|
540
|
+
textColor: true,
|
|
541
|
+
highlightColor: true,
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
});
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
### Custom Stylesheet
|
|
550
|
+
|
|
551
|
+
You can inject custom CSS to style the editor content area. There are two options — use one or the other, not both.
|
|
552
|
+
|
|
553
|
+
**Option 1: `css`** — Inline CSS content (recommended for monorepos and production deployments)
|
|
554
|
+
|
|
555
|
+
Read the file at Strapi startup so the CSS is captured as a string. This works reliably across all environments (local dev, Docker, Azure Container Apps, etc.) because the file is resolved in your app's Node process at boot time.
|
|
556
|
+
|
|
557
|
+
```ts
|
|
558
|
+
// config/plugins.ts
|
|
559
|
+
import { readFileSync } from 'fs';
|
|
560
|
+
|
|
561
|
+
export default () => ({
|
|
562
|
+
'tiptap-editor': {
|
|
563
|
+
config: {
|
|
564
|
+
theme: {
|
|
565
|
+
css: readFileSync(require.resolve('@repo/design-system/strapi-styles.css'), 'utf-8'),
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
**Option 2: `stylesheet`** — A URL the browser can fetch directly
|
|
573
|
+
|
|
574
|
+
Use this when the stylesheet is hosted at a known URL (CDN, public path, etc.).
|
|
575
|
+
|
|
576
|
+
```ts
|
|
577
|
+
// config/plugins.ts
|
|
578
|
+
|
|
579
|
+
export default () => ({
|
|
580
|
+
'tiptap-editor': {
|
|
581
|
+
config: {
|
|
582
|
+
theme: {
|
|
583
|
+
stylesheet: 'https://cdn.example.com/editor-styles.css',
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
});
|
|
588
|
+
```
|
|
589
|
+
|
|
419
590
|
## Configuration Reference
|
|
420
591
|
|
|
421
592
|
### Feature Values
|
|
@@ -474,8 +645,14 @@ export default () => ({
|
|
|
474
645
|
// Text alignment (left, center, right, justify)
|
|
475
646
|
textAlign: true,
|
|
476
647
|
|
|
477
|
-
//
|
|
478
|
-
|
|
648
|
+
// Text and highlight colors (requires theme.colors)
|
|
649
|
+
textColor: true,
|
|
650
|
+
highlightColor: true,
|
|
651
|
+
|
|
652
|
+
// Images from Strapi Media Library with resize enabled
|
|
653
|
+
mediaLibrary: {
|
|
654
|
+
resize: { enabled: true },
|
|
655
|
+
},
|
|
479
656
|
},
|
|
480
657
|
},
|
|
481
658
|
},
|
package/package.json
CHANGED