@notum-cz/strapi-plugin-tiptap-editor 1.1.1 → 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 +82 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
- [Text Alignment](#text-alignment)
|
|
91
91
|
- [Text Color \& Highlight Color](#text-color--highlight-color)
|
|
92
92
|
- [Images](#images)
|
|
93
|
+
- [Rendering images on the frontend](#rendering-images-on-the-frontend)
|
|
93
94
|
- [Theme](#theme)
|
|
94
95
|
- [Colors](#colors)
|
|
95
96
|
- [Custom Stylesheet](#custom-stylesheet)
|
|
@@ -415,18 +416,22 @@ Both features use a color picker popover that displays the colors defined in the
|
|
|
415
416
|
|
|
416
417
|
### Images
|
|
417
418
|
|
|
418
|
-
| Key | Description | Toolbar
|
|
419
|
-
| -------------- | -------------------------------- |
|
|
420
|
-
| `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 |
|
|
421
422
|
|
|
422
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:
|
|
423
424
|
|
|
424
425
|
- The image appears in the editor at its natural size (constrained to editor width)
|
|
425
426
|
- Alt text is prefilled from the asset's `alternativeText` metadata
|
|
426
|
-
- Clicking a selected image opens a popover
|
|
427
|
-
- 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
|
|
428
433
|
|
|
429
|
-
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.
|
|
430
435
|
|
|
431
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.
|
|
432
437
|
|
|
@@ -436,6 +441,73 @@ The image stores both the URL (`src`) and the Strapi asset ID (`data-asset-id`)
|
|
|
436
441
|
}
|
|
437
442
|
```
|
|
438
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
|
+
|
|
439
511
|
## Theme
|
|
440
512
|
|
|
441
513
|
The `theme` key in the plugin config lets you define colors for the color pickers and inject custom CSS into the editor.
|
|
@@ -577,8 +649,10 @@ export default () => ({
|
|
|
577
649
|
textColor: true,
|
|
578
650
|
highlightColor: true,
|
|
579
651
|
|
|
580
|
-
// Images from Strapi Media Library
|
|
581
|
-
mediaLibrary:
|
|
652
|
+
// Images from Strapi Media Library with resize enabled
|
|
653
|
+
mediaLibrary: {
|
|
654
|
+
resize: { enabled: true },
|
|
655
|
+
},
|
|
582
656
|
},
|
|
583
657
|
},
|
|
584
658
|
},
|
package/package.json
CHANGED